Chain of command

Company: Imc_7aug

Difficulty: medium

Problem Statement

Chain of command Problem Description An organization of n people is structured as a rooted tree. The people are numbered 1 to n , and person 1 is the root. Every person other than the root has exactly one direct manager (their parent in the tree), and a person may have any number of direct reports (their children). The tree is given as an array parent of length n : parent[0] = -1 marks person 1 as the root, and for every person i with 2 <= i <= n , parent[i - 1] is the direct manager of person i . A directive issued by a person propagates through everyone below them as follows: The issuer receives the directive first. A person passes the directive to their direct reports in ascending order of their numbers . If a person has more than one direct report, they wait until the directive has propagated fully through one report's entire subtree before passing it to the next report. Every person who receives the directive propagates it to their own subtree by the same process, and propag