n processes that form a tree: every process except a single root has a parent, the process that launched it. ids[i] is the id of the i-th process and parents[i] is the id of its parent; for the root, parents[i] = 0.
When a process is stopped, all of its children stop with it, and their children too, and so on.
Return the ids of every process that stops when you stop process target. The order does not matter.ids=[4, 8, 2, 6, 9], parents=[0, 4, 4, 8, 8], target=8 → [8, 6, 9]
Process 8 started 6 and 9, so 8, 6 and 9 stop. Processes 4 and 2 keep running.
ids=[3, 1, 5], parents=[5, 3, 0], target=5 → [5, 3, 1]
5 is the root of the whole tree, so everything stops.
ids=[7], parents=[0], target=7 → [7]
ids) = len(parents) ≤ 5·10⁴ids[i] ≤ 5·10⁴, all ids are distinctparents[i] ≤ 5·10⁴parents[i] = 0, and the links form a treetarget is one of the idsids=[4, 8, 2, 6, 9], parents=[0, 4, 4, 8, 8], target=8
[8, 6, 9]
Run checks the first 3 tests in your browser. Submit checks all 64 tests on the server, hidden ones included.