#P9358. [ICPC 2022 Xi'an R] Bridge
[ICPC 2022 Xi'an R] Bridge
题目描述
There are countries numbered from to in Erathia. Each country can be regarded as a chain with nodes numbered from to . Initially, node is connected with node by a street where node denotes the -th node of the -th country. There are no bridges between any two countries at first.
You need to process queries of the following two types.
- (). Build a bridge between node and node . It is guranteed that at any time, each node is connected with at most one bridge.
- (). A hero will walk through Erathia. This hero starts from . If the hero is at and there is a unvisited bridge connected to him, he passes it, or he goes to . Once he arrived the -th node of any conutry, he stops. Please note that 'unvisited bridge' is independently judged for each query.
Your task is to print which country the hero is in at last for the second kind of query. It can be proved that the hero's route is always unique under these constraints.
输入格式
The first line contains three integers , and ().
Each of the following lines represents a query with format described above.
输出格式
For each query of type , output a line with an integer representing the answer.
3 4 13
2 2
1 1 3
2 1
2 2
2 3
1 2 4
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3
2
2
1
3
3
1
2
3
2
1
提示
Source: The 2022 ICPC Asia Xi'an Regional Contest Problem A.
Author: MonkeyKing.