B. Find The Bone
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nm, 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 ≤ nui ≠ 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
7 3 4
3 4 6
1 2
2 5
5 7
7 1
output
1
input
5 1 2
2
1 2
2 4
output
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.

题意:

有n个杯子,m个杯子底下有洞,将骨头交换k次,遇到洞就会掉下去不动,求最后骨头的位置。

注意交换的两个位置是不分先后的。

AC代码:

 #include<bits/stdc++.h>
using namespace std; int main(){
ios::sync_with_stdio(false);
int h[];
int n,m,k,t,s,flag=,ans=;
cin>>n>>m>>k;
//scanf("%d%d%d",&n,&m,&k);
memset(h,,sizeof(h));
for(int i=;i<m;i++){
cin>>t;
//scanf("%d",&t);
h[t]=;
}
if(h[]){
flag=;
}
for(int i=;i<k;i++){
cin>>t>>s;
//scanf("%d%d",&t,&s);
if(!h[t]&&ans==t){
ans=s;
}
else if(!h[s]&&ans==s){
ans=t;
}
}
cout<<ans<<endl;
return ;
}

CF-796B的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  10. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

随机推荐

  1. Android调用JNI本地方法跟踪目标代码

    正如Android调用JNI本地方法经过有点改变章所说跟踪代码是可行的,但是跟踪某些代码会出现anr,点击取消,还是不好运,有提高办法吗?回答是有(gdb还没试过,本文只讨论ida). 下面是我使用  ...

  2. poj 1703 Find them, Catch them(种类并查集和一种巧妙的方法)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36176   Accepted: ...

  3. Ubuntu 16.04 引导修复(Boot Repair)----lianwang----anzhuang windows hou(双系统修复一)

    2016-01-26 20:54 12548人阅读 评论(1) 收藏 举报 分类: =======学习心得=======(23) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] ...

  4. (转)Understanding C parsers generated by GNU Bison

    原文链接:https://www.cs.uic.edu/~spopuri/cparser.html Satya Kiran PopuriGraduate StudentUniversity of Il ...

  5. centos7 设置网络

    https://lintut.com/how-to-setup-network-after-rhelcentos-7-minimal-installation/ First, type “nmcli ...

  6. xpath 节点1

    XPath 含有超过 100 个内建的函数.这些函数用于字符串值.数值.日期和时间比较.节点和 QName 处理.序列处理.逻辑值等等. 节点(Node) 在 XPath 中,有七种类型的节点:元素. ...

  7. unity3d开发的android应用中增加AD系统的详细步骤

    unity3d开发的android应用中增加AD系统的详细步骤 博客分类: Unity3d unity3d  Unity3d已经支持android,怎样在程序里增加admob?  试了一下,确实能够, ...

  8. Nothing but the key 属性全部依赖于主键 third norm form

    全依赖 Designs that Violate 1NF CustomerCustomer ID First Name Surname Telephone Number123 Pooja Singh ...

  9. 使用注解来构造IoC容器-转

    新手,对于一些觉得有用的东西,直接转过来用了,自己理解的比较肤浅 使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<co ...

  10. Android笔记之为TextView设置边框

    效果图 text_view_background.xml <?xml version="1.0" encoding="utf-8"?> <sh ...