博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF796B Find The Bone
阅读量:6606 次
发布时间:2019-06-24

本文共 4014 字,大约阅读时间需要 13 分钟。

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.

Input

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.

Output

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

Examples
Input
Copy
7 3 4 3 4 6 1 2 2 5 5 7 7 1
Output
Copy
1
Input
Copy
5 1 2 2 1 2 2 4
Output
Copy
2
Note

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.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
//#pragma GCC optimize(2)using namespace std;#define maxn 1000005#define inf 0x7fffffff//#define INF 1e18#define rdint(x) scanf("%d",&x)#define rdllt(x) scanf("%lld",&x)#define rdult(x) scanf("%lu",&x)#define rdlf(x) scanf("%lf",&x)#define rdstr(x) scanf("%s",x)typedef long long ll;typedef unsigned long long ull;typedef unsigned int U;#define ms(x) memset((x),0,sizeof(x))const long long int mod = 1e9 + 7;#define Mod 1000000000#define sq(x) (x)*(x)#define eps 1e-4typedef pair
pii;#define pi acos(-1.0)//const int N = 1005;#define REP(i,n) for(int i=0;i<(n);i++)typedef pair
pii;inline ll rd() { ll x = 0; char c = getchar(); bool f = false; while (!isdigit(c)) { if (c == '-') f = true; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return f ? -x : x;}ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b);}int sqr(int x) { return x * x; }/*ll ans;ll exgcd(ll a, ll b, ll &x, ll &y) { if (!b) { x = 1; y = 0; return a; } ans = exgcd(b, a%b, x, y); ll t = x; x = y; y = t - a / b * y; return ans;}*/int n, m, k;int h[maxn];bool fg[maxn];int main() { //ios::sync_with_stdio(0); cin >> n >> m >> k; for (int i = 1; i <= m; i++)rdint(h[i]), fg[h[i]] = 1; int posbon = 1; bool flag = 0; if (fg[posbon]) { flag = 1; } for (int i = 1; i <= k; i++) { int u, v; rdint(u); rdint(v); if (flag)continue; if (u == posbon) { posbon = v; } else if (v == posbon) { posbon = u; } if (fg[posbon]) { flag = 1; } } cout << posbon << endl; return 0;}

 

转载于:https://www.cnblogs.com/zxyqzy/p/10282985.html

你可能感兴趣的文章
Hibernate导出表代码
查看>>
用户输入和while循环
查看>>
将datatable 保存为 Excel文件(高效率版本)
查看>>
C/C++五大内存分区(转)
查看>>
System V 共享内存区
查看>>
springmvc_1(hello world)
查看>>
0.随笔——读后感
查看>>
StringUtils类方法解析
查看>>
CentOS 6.5下PXE+Kickstart无人值守安装操作系统
查看>>
Nginx ssl/https 配置
查看>>
客户端通过TCP通信分页从服务器获取数据
查看>>
HTTP协议包头分析
查看>>
HNUSTOJ-1600 BCD时钟
查看>>
xtrapivotcontrol 控件用法及相关属性
查看>>
[c++] How many bytes do pointers take up?
查看>>
使用Git和Github来管理自己的代码和笔记
查看>>
Shell脚本 常用命令总结 二
查看>>
Centos(Yum源更改)
查看>>
冰球游戏大概的模块
查看>>
PHP中htmlentities和htmlspecialchars的区别
查看>>