CF796B.Find The Bone

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Zane the wizard is going to perform a magic show shuffling the cups.

There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i.

The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = u__i and x = v__i. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations.

Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation.

Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone.

巫师赞恩将进行一场杯子洗牌的魔术表演。

桌上有 nn 个杯子,编号从 11 到 nn,沿 xx 轴放置在一张有 mm 个洞的桌子上。更准确地说,杯子 ii 位于桌面上的 x=ix = i 处。

那根“麻烦的骨头”初始时位于 x=1x = 1 处。赞恩将通过 kk 次交换操作来迷惑观众,其中第 ii 次操作交换位于 x=uix = u_i 和 x=vix = v_i 处的两个杯子。若骨头在任意时刻恰好处于一个有洞的位置,它便会掉入洞中落到地面,并不再受后续任何交换操作的影响。

别忘了赞恩是一位巫师!当他交换杯子时,并非以常规方式移动它们;相反,他会将杯子(连同其中可能存在的骨头)直接瞬移到目标位置。因此,例如当他交换位于 x=4x = 4 和 x=6x = 6 的杯子时,在操作过程中它们绝不会出现在 x=5x = 5 处。

赞恩的小狗因赞恩(Inzane)遇到了麻烦。赞恩正在度假,而因赞恩找不到他心爱的骨头——因为逐一打开所有杯子实在太费力了。因赞恩知道 Codeforces 社区曾成功帮助过赞恩,因此他想看看大家是否也能帮他解决这个难题。请帮助因赞恩确定骨头的最终位置。

输入格式

The first line contains three integers n, m, and k (2 ≤ n ≤ 106, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·105) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains m distinct integers _h_1, _h_2, ..., h__m (1 ≤ h__i ≤ n) — the positions along the x-axis where there is a hole on the table.

Each of the next k lines contains two integers u__i and v__i (1 ≤ u__i, v__i ≤ n, u__i ≠ v__i) — the positions of the cups to be swapped.

第一行包含三个整数 nn、mm 和 kk(2 ≤ n ≤ 1062 \leq n \leq 10^6,1 ≤ m ≤ n1 \leq m \leq n,1 ≤ k ≤ 3⋅1051 \leq k \leq 3\cdot10^5),分别表示杯子的数量、桌面上孔洞的数量以及交换操作的次数。

第二行包含 mm 个互不相同的整数 h1, h2, ..., hmh_1,\,h_2,\,...,\,h_m(1 ≤ hi ≤ n1 \leq h_i \leq n),表示桌面上孔洞在 xx 轴上的位置。

接下来的 kk 行中,每行包含两个整数 uiu_i 和 viv_i(1 ≤ ui, vi ≤ n1 \leq u_i,\,v_i \leq n,ui ≠ viu_i \neq v_i),表示将要被交换的两个杯子的位置。

输出格式

Print one integer — the final position along the x-axis of the bone.

输出一个整数——骨头最终在 xx 轴上的位置。

输入输出样例

  • 输入#1

    7 3 4
    3 4 6
    1 2
    2 5
    5 7
    7 1

    输出#1

    1
  • 输入#2

    5 1 2
    2
    1 2
    2 4

    输出#2

    2

说明/提示

In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively.

In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground.

在第一个样例中,经过各次操作后,骨头分别位于 x=2x = 2、x=5x = 5、x=7x = 7 和 x=1x = 1 处。

在第二个样例中,经过第一次操作后,骨头位于 x=2x = 2 处,并掉入洞中落到地面。

输入解题思路,AI测评打分。不知道怎么写?

首页