| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 6 초 | 1024 MB | 8 | 5 | 5 | 71.429% |
Your task is to maintain a colourful tree and process queries.
At the beginning, there is only one vertex numbered 1ドル$ with colour $C$ on the tree. Then there are $q$ operations of two types coming in order:
After each operation, you should find a pair of vertices $u$ and $v$ (1ドル ≤ u, v ≤ n$) with different colours in the current tree so that the distance between $u$ and $v$ is as large as possible.
The distance between two vertices $u$ and $v$ is the length of the shortest path from $u$ to $v$ on the tree.
There are multiple test cases. The first line of the input contains an integer $T$ indicating the number of test cases. For each test case:
The first line of the input contains two integers $q$ and $C$ (1ドル ≤ q ≤ 5 \times 10^5,ドル 1ドル ≤ C ≤ q$) indicating the number of operations and the initial colour of vertex 1ドル$.
For the following $q$ lines, each line describes an operation taking place in order with 3ドル$ or 4ドル$ integers.
It’s guaranteed that the sum of $q$ of all test cases will not exceed 5ドル \times 10^5$.
For each operation output the maximum distance between two vertices with different colours. If no valid pair exists output 0ドル$ instead.
2 1 1 0 1 1 1 5 1 0 1 1 1 0 1 2 1 0 3 3 1 1 4 1 1 3 1
0 0 2 3 2 0