CF796B.Find The Bone

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

There are nn cups, numbered from 11 to nn , placed along the xx -axis on a table that has mm holes on it. More precisely, cup ii is on the table at the position x=ix=i .

The problematic bone is initially at the position x=1x=1 . Zane will confuse the audience by swapping the cups kk times, the ii -th time of which involves the cups at the positions x=uix=u_{i} and x=vix=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=4x=4 and the one at x=6x=6 , they will not be at the position x=5x=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.

输入格式

The first line contains three integers nn , mm , and kk ( 2<=n<=1062<=n<=10^{6} , 1<=m<=n1<=m<=n , 1<=k<=31051<=k<=3·10^{5} ) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively.

The second line contains mm distinct integers h1,h2,...,hmh_{1},h_{2},...,h_{m} ( 1<=hi<=n1<=h_{i}<=n ) — the positions along the xx -axis where there is a hole on the table.

Each of the next kk lines contains two integers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} ) — the positions of the cups to be swapped.

输出格式

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

输入输出样例

  • 输入#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=2x=2 , x=5x=5 , x=7x=7 , and x=1x=1 , respectively.

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

首页