Save the Universe

Problem Overview

  • Given a rooted tree of universes with evil numbers, split it into vertical branches.
  • Each branch can contain at most m nodes, and the total evil across all branches must be < k.
  • Goal: minimize the number of branches; output -1 if it cannot be done.
  • Input: n, m, k; evil array e[1..n]; parent list p[2..n]; n, m <= 1e5; values up to 1e18.
  • From Rubrik interviews: a coding interview problem in a multiverse setting and a solid interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: