#abc295g. G - Minimum Reachable City
G - Minimum Reachable City
Score : points
问题描述
我们有一个有向图 ,包含 个顶点,编号为 到 。它有 条边。第 条边()从顶点 指向顶点 。
我们还有一个有向图 ,同样包含 个顶点,编号也是 到 。最初, 等于 。按照给定顺序对 进行 个查询操作。查询有两种类型,如下所示。
1 u v
:在 中添加一条从顶点 指向顶点 的边。保证满足以下条件:- 。
- 在 上,通过一些边可以从顶点 达到顶点 。
2 x
:输出一个可以通过 上的一些边(包括顶点 自身的边)从顶点 达到的最小顶点编号。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a directed graph with vertices numbered to . It has edges. The -th edge goes from vertex to vertex .
We have another directed graph with vertices numbered to . Initially, equals . Process queries on in the order they are given. There are two kinds of queries as follows.
1 u v
: Add an edge to that goes from vertex to vertex . It is guaranteed that the following conditions are satisfied.- .
- On , vertex is reachable from vertex via some edges.
2 x
: Print the smallest vertex number of a vertex reachable from vertex via some edges on (including vertex ).
Constraints
- For each query in the first format:
- .
- .
- On , vertex is reachable from vertex via some edges.
- For each query in the second format, .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Here, denotes the -th query and is in one of the following formats:
Output
Print lines, where is the number of queries in the second format. The -th line should contain the answer to the -th query in the second format.
Sample Input 1
5
1 2 3 3
5
2 4
1 4 2
2 4
1 5 1
2 4
Sample Output 1
4
2
1
- At the time of the first query, only vertex is reachable from vertex via some edges on .
- At the time of the third query, vertices , , , and are reachable from vertex via some edges on .
- At the time of the fifth query, vertices , , , , and are reachable from vertex via some edges on .
Sample Input 2
7
1 1 2 2 3 3
10
2 5
1 5 2
2 5
1 2 1
1 7 1
1 6 3
2 5
2 6
2 1
1 7 1
Sample Output 2
5
2
1
1
1
update @ 2024/3/10 12:17:02