CF1416D.Graph and Queries
省选/NOI-
通过率:0%
时间限制:1.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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).
给你一个包含 n 个顶点和 m 条边的无向图。初始时,每个顶点上都写有一个整数:顶点 i 上写有 pi。所有 pi 均为 1 到 n 之间互不相同的整数。
你需要处理 q 个查询,查询分为两类:
- 1 v — 在所有可通过图中的边从顶点 v 到达的顶点(包括顶点 v 本身)中,找出写有最大数值 pu 的顶点 u,输出 pu,并将 pu 替换为 0;
- 2 i — 从图中删除第 i 条边。
注意:对于第一类查询,有可能从 v 可达的所有顶点上写的数均为 0。此时,u 并未被明确定义;但由于 u 的选取不影响任何结果,你可以任选一个从 v 可达的顶点,并输出其值(即 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.
第一行包含三个整数 n、m 和 q(1≤n≤2⋅105;1≤m≤3⋅105;1≤q≤5⋅105)。
第二行包含 n 个互不相同的整数 p1, p2, ..., pn,其中 pi 表示顶点 i 上初始写入的数字(1≤pi≤n)。
接下来是 m 行,第 i 行包含两个整数 ai 和 bi(1≤ai,bi≤n,ai=bi),表示第 i 条边连接顶点 ai 和 bi。保证图中不含重边。
接下来是 q 行,描述各查询。每行采用以下两种格式之一:
- 1 v — 表示类型一的查询,参数为顶点 v(1≤v≤n)。
- 2 i — 表示类型二的查询,参数为边 i(1≤i≤m)。对于每个类型二的查询,保证对应的边尚未从图中删除。
输出格式
For every query of the first type, print the value of pu written on the chosen vertex u.
对于每个第一类查询,输出所选顶点 u 上写的值 pu。
输入输出样例
输入#1
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
输出#1
5 1 2 0
输入解题思路,AI测评打分。不知道怎么写?