atcoder#ABC274C. [ABC274C] Ameba
[ABC274C] Ameba
Score : points
Problem Statement
You observed amoebae and kept some records.
Initially, there was one amoeba, numbered .
You made records. According to the -th record, the amoeba numbered disappeared by dividing itself into two new amoebae, which were then numbered and . Here, amoeba is said to be the parent of amoebae and .
For each , how many generations away is amoeba from amoeba ?
Constraints
- The records are consistent. That is:- .
- are distinct integers.
- .
- are distinct integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the generation distance between amoeba and amoeba .
2
1 2
0
1
1
2
2
From amoeba , amoebae and were born. From amoeba , amoebae and were born.
- Amoeba is zero generations away from amoeba .
- Amoeba is one generation away from amoeba .
- Amoeba is one generation away from amoeba .
- Amoeba is one generation away from amoeba , and two generations away from amoeba .
- Amoeba is one generation away from amoeba , and two generations away from amoeba .
4
1 3 5 2
0
1
1
2
2
3
3
2
2