NewThe Learning module is now liveSee what's new

You are given a sewer drainage system shaped as a rooted tree with n nodes labeled from 0 to n-1. Water flows upwards from each node to the root node 0, then exits the system.

The tree is described by two arrays:

  • parent of length n, where parent[i] is the direct parent of node i (the next node water flows to). And parent[0] is -1 because the root has no parent.
Test Cases
Input
Output
Expected