F. Graph and Queries SOLUTION Codeforces Round #673 (Div. 2)

Graph and Queries SOLUTION

You are given an undirected graph consisting of n vertices and m edges. Initially there is a single integer written on every vertex: the vertex i has pi written on it. All pi are distinct integers from 1 to n.
You have to process q queries of two types:
1 v — among all vertices reachable from the vertex v using the edges of the graph (including the vertex v itself), find a vertex u with the largest number pu written on it, print pu and replace pu with 0;
2 i — delete the i-th edge from the graph.
Note that, in a query of the first type, it is possible that all vertices reachable from v have 0 written on them. In this case, u is not explicitly defined, but since the selection of u does not affect anything, you can choose any vertex reachable from v and print its value (which is 0).
The first line contains three integers n, m and q (1≤n≤2⋅105; 1≤m≤3⋅105; 1≤q≤5⋅105).
The second line contains n distinct integers p1, p2, …, pn, where pi is the number initially written on vertex i (1≤pi≤n).
Then m lines follow, the i-th of them contains two integers ai and bi (1≤ai,bi≤n, ai≠bi) and means that the i-th edge connects vertices ai and bi. It is guaranteed that the graph does not contain multi-edges.
Then q lines follow, which describe the queries. Each line is given by one of the following formats:
1 v — denotes a query of the first type with a vertex v (1≤v≤n).
2 i — denotes a query of the second type with an edge i (1≤i≤m). For each query of the second type, it is guaranteed that the corresponding edge is not deleted from the graph yet.
For every query of the first type, print the value of pu written on the chosen vertex u.
5 4 6
1 2 5 4 3
1 2
2 3
1 3
4 5
1 1
2 1
2 3
1 1
1 2
1 2

Leave a Comment

four × 1 =