CF1416D.Graph and Queries

省选/NOI-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an undirected graph consisting of nn vertices and mm edges. Initially there is a single integer written on every vertex: the vertex ii has pip_i written on it. All pip_i are distinct integers from 11 to nn.

You have to process qq queries of two types:

  • 11 vv — among all vertices reachable from the vertex vv using the edges of the graph (including the vertex vv itself), find a vertex uu with the largest number pup_u written on it, print pup_u and replace pup_u with 00;
  • 22 ii — delete the ii-th edge from the graph.

Note that, in a query of the first type, it is possible that all vertices reachable from vv have 00 written on them. In this case, uu is not explicitly defined, but since the selection of uu does not affect anything, you can choose any vertex reachable from vv and print its value (which is 00).

给你一个包含 nn 个顶点和 mm 条边的无向图。初始时,每个顶点上都写有一个整数:顶点 ii 上写有 pip_i。所有 pip_i 均为 11 到 nn 之间互不相同的整数。

你需要处理 qq 个查询,查询分为两类:

  • 11 vv — 在所有可通过图中的边从顶点 vv 到达的顶点(包括顶点 vv 本身)中,找出写有最大数值 pup_u 的顶点 uu,输出 pup_u,并将 pup_u 替换为 00;
  • 22 ii — 从图中删除第 ii 条边。

注意:对于第一类查询,有可能从 vv 可达的所有顶点上写的数均为 00。此时,uu 并未被明确定义;但由于 uu 的选取不影响任何结果,你可以任选一个从 vv 可达的顶点,并输出其值(即 00)。

输入格式

The first line contains three integers nn, mm and qq (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤m≤3⋅1051 \le m \le 3 \cdot 10^5; 1≤q≤5⋅1051 \le q \le 5 \cdot 10^5).

The second line contains nn distinct integers p1p_1, p2p_2, ..., pnp_n, where pip_i is the number initially written on vertex ii (1≤pi≤n1 \le p_i \le n).

Then mm lines follow, the ii-th of them contains two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n, ai≠bia_i \ne b_i) and means that the ii-th edge connects vertices aia_i and bib_i. It is guaranteed that the graph does not contain multi-edges.

Then qq lines follow, which describe the queries. Each line is given by one of the following formats:

  • 11 vv — denotes a query of the first type with a vertex vv (1≤v≤n1 \le v \le n).
  • 22 ii — denotes a query of the second type with an edge ii (1≤i≤m1 \le i \le m). For each query of the second type, it is guaranteed that the corresponding edge is not deleted from the graph yet.

第一行包含三个整数 nn、mm 和 qq(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤m≤3⋅1051 \le m \le 3 \cdot 10^5;1≤q≤5⋅1051 \le q \le 5 \cdot 10^5)。

第二行包含 nn 个互不相同的整数 p1p_1, p2p_2, ..., pnp_n,其中 pip_i 表示顶点 ii 上初始写入的数字(1≤pi≤n1 \le p_i \le n)。

接下来是 mm 行,第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \le a_i, b_i \le n,ai≠bia_i \ne b_i),表示第 ii 条边连接顶点 aia_i 和 bib_i。保证图中不含重边。

接下来是 qq 行,描述各查询。每行采用以下两种格式之一:

  • 11 vv — 表示类型一的查询,参数为顶点 vv(1≤v≤n1 \le v \le n)。
  • 22 ii — 表示类型二的查询,参数为边 ii(1≤i≤m1 \le i \le m)。对于每个类型二的查询,保证对应的边尚未从图中删除。

输出格式

For every query of the first type, print the value of pup_u written on the chosen vertex uu.

对于每个第一类查询,输出所选顶点 uu 上写的值 pup_u。

输入输出样例

  • 输入#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测评打分。不知道怎么写?

首页