luogu#P9358. [ICPC2022 Xi'an R] Bridge
[ICPC2022 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.
题目大意
题目描述
Erathia 大陆上有 个国家,从 到 编号。每个国家可以看成由 个结点组成的链,结点从 到 编号。结点 和 由一条街道连接,其中 表示国家 的第 个结点。一开始,国家之间没有桥。
你需要处理 个操作:
- (,):在 和 之间建造一座桥。保证每个结点最多和一座桥相连。
- ():一名英雄走过 Erathia 大陆。他从 出发。如果这名英雄当前在结点 且有一座未被访问过的桥与之连接,那么他会走过这个桥到达桥的另一端,否则他会走到 。一旦他到达某个国家的第 个结点,他就会停下来。注意两个询问之间的 “未被访问过的桥” 是独立的。
你的任务是对每个操作 求出英雄最终所在的国家。
。
输入格式
第一行三个整数 。
接下来 行,每行若干个整数表示一组询问。格式见题目描述。
输出格式
对于每个操作 ,输出一行一个整数表示答案。
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.