Cossack Vus and the Count
You are given a graph with vertices and queries of three types:
For a given vertex , find the -th smallest vertex number in its connected component. If such a vertex does not exist, return . The connected component of includes all vertices reachable from via edges.
Add an edge between vertices and .
Revert the graph to its state after the -th operation.
Your task is to provide answers for all queries of the first type.
Giriş verilənləri
The first line contains three integers , , and (, ).
Each of the following lines contains a query in one of the following formats:
, ().
, ().
().
Çıxış verilənləri
For each query of the first type, output the result.
Nümunələr
Qiymətləndirmə
( points): ; no queries of the second and third types.
( points): ; no queries of the third type.
( points): .
( points): ; for queries of the second type, it is guaranteed that ; no queries of the third type.
( points): , no queries of the third type.
( points): ; for queries of the second type, it is guaranteed that .
( points): .
( points): .
( points): no additional constraints.