Ouestion 2:
Path MEX
You are given a rooted tree having N nodes. A tree is connected undirected graph with N-1 edges. Here root nodes 1. Each nodes has some integer value val, associated with it.
Task
For each each node i(1<=i<=N), print MEX of the path values form the root node to node i.
Notes
- Assume 1-based indexing
- The MEX of an array is equal to the samllest positive iinteger that is not present in array. For example, MEX(1, 2, 4, 2, 3, 6, 7)=5.
Sample input
1
6
1 3 2 2 4 2
1 1 2 2 5
Sample Output
2 2 3 4 2 5