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:
parentof lengthn, whereparent[i]is the direct parent of nodei(the next node water flows to). Andparent[0]is-1because the root has no parent.
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected