Problem
Input format
The first line contains the natural number `n`. The second line contains `n` non-negative integers separated by spaces, representing the values `t[1], t[2], ..., t[n]` of the parent array. - `1 <= n <= 100` - `0 <= t[i] <= n` for every `i` in `1..n` - the array describes a valid tree, so there is exactly one value equal to `0`
Output format
The program prints a single natural number: the index of the root.
Example
7 2 4 4 0 4 5 5
4
Stuck?
Use the Get Hint button in the action bar to reveal a guided hint.
💬 Discussion
Loading...No comments yet. Be the first to start the discussion!
Sample cases (from the problem)
Sample Case 1
7 2 4 4 0 4 5 5
4
Solve it your way first
Community solutions unlock after you submit a passing solution. Don't peek.
Ready to solve this challenge?
Create a free account to write code, submit solutions, and track your progress.