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 = ui and x = vi. 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.
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 h1, h2, ..., hm (1 ≤ hi ≤ n) — the positions along the x-axis where there is a hole on the table.
Each of the next k lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the positions of the cups to be swapped.
Print one integer — the final position along the x-axis of the bone.
7 3 4 3 4 6 1 2 2 5 5 7 7 1
1
5 1 2 2 1 2 2 4
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.
题目大意:
给你N个盒子,第一个盒子一开始装着骨头,现在有m个位子上有漏洞,如果带有骨头的盒子移动到了这些位子上,那么骨头就会掉在漏洞上再也不会动。
问最终骨头在哪里、
每一次操作交换两个位子上的盒子。
思路:
模拟即可。
Ac代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int vis[1000050];
int a[1000050];
int main()
{
int n,m,k;
while(~scanf("%d%d%d",&n,&m,&k))
{
memset(vis,0,sizeof(vis));
for(int i=0;i<m;i++)
{
int x;
scanf("%d",&x);
vis[x]=1;
}
int ans=1;
while(k--)
{
int x,y;
scanf("%d%d",&x,&y);
if(x==ans)
{
if(vis[x]!=1)ans=y;
}
else if(y==ans)
{
if(vis[y]!=1)ans=x;
}
}
printf("%d\n",ans);
}
}