#abc372e. E - K-th Largest Connected Components
E - K-th Largest Connected Components
Score : points
问题陈述
有一个无向图,包含 个顶点和 条边。顶点编号从 到 。
你需要按顺序处理 个查询。每个查询是以下两种类型之一:
- 类型 :格式为
1 u v
。在顶点 和 之间添加一条边。 - 类型 :格式为
2 v k
。打印与顶点 相连的顶点中第 大的顶点编号。如果与 相连的顶点少于 个,则打印-1
。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is an undirected graph with vertices and edges. The vertices are numbered to .
You are given queries to process in order. Each query is of one of the following two types:
- Type : Given in the format
1 u v
. Add an edge between vertices and . - Type : Given in the format
2 v k
. Print the -th largest vertex number among the vertices connected to vertex . If there are fewer than vertices connected to , print-1
.
Constraints
- In a Type query, .
- In a Type query, , .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Here, is the -th query and is given in one of the following formats:
Output
Let be the number of Type queries. Print lines. The -th line should contain the answer to the -th Type query.
Sample Input 1
4 10
1 1 2
2 1 1
2 1 2
2 1 3
1 1 3
1 2 3
1 3 4
2 1 1
2 1 3
2 1 5
Sample Output 1
2
1
-1
4
2
-1
- In the first query, an edge is added between vertices and .
- In the second query, two vertices are connected to vertex : and . Among them, the -st largest vertex number is , which should be printed.
- In the third query, two vertices are connected to vertex : and . Among them, the -nd largest vertex number is , which should be printed.
- In the fourth query, two vertices are connected to vertex : and , which is fewer than , so print
-1
. - In the fifth query, an edge is added between vertices and .
- In the sixth query, an edge is added between vertices and .
- In the seventh query, an edge is added between vertices and .
- In the eighth query, four vertices are connected to vertex : . Among them, the -st largest vertex number is , which should be printed.
- In the ninth query, four vertices are connected to vertex : . Among them, the -rd largest vertex number is , which should be printed.
- In the tenth query, four vertices are connected to vertex : , which is fewer than , so print
-1
.
Sample Input 2
6 20
1 3 4
1 3 5
2 1 1
2 3 1
1 1 5
2 6 9
2 1 3
2 6 1
1 4 6
2 2 1
2 6 2
2 4 7
1 1 4
2 6 2
2 3 4
1 2 5
2 4 1
1 1 6
2 3 3
2 1 3
Sample Output 2
1
5
-1
3
6
2
5
-1
5
3
6
4
4