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 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
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个杯子标号为(1~n),有m个杯子有洞,有k次操作,

每次操作交换编号为u和编号为v的杯子,如果这个杯子 有洞,骨头就会掉下去,

初始骨头在位置1,现在问你k此操作以后骨头在哪里

解析:标记洞编号,每次交换前判断骨头是否掉入洞中,

如果交换的两个杯子中没有骨头,骨头位置没有变,不用处理

如果交换的两个杯子中有骨头,在 ui 中,并且骨头未掉入洞中, 骨头位置变化到 vi 中

在 vi 中,并且骨头未掉入洞中, 骨头位置变换到 ui 中

重复 K 次操作,最后找到 骨头的位置

另:用cin cout 可能会超时,较大数据用scanf(); printf();

 #include <iostream>
#include <cstdio>
using namespace std;
const int M = 1e6 +;
int holes[M];
int main(){
int n, m, k;
scanf("%d%d%d",&n,&m,&k);
//cin >> n >> m >> k;
int stone = ;
for(int i = ; i < m; i++){
int hol;
//cin >. hol;
scanf("%d",&hol);
holes[hol] ++;
}
for(int i = ; i < k; i++){
int ui, vi;
//cin >> ui >> vi;
scanf("%d%d",&ui,&vi);
if(ui == stone && holes[ui] != ){
stone = vi;
}
else if(vi == stone && holes[vi] != ){
stone = ui;
}
}
//cout << stone << endl;
printf("%d",stone);
}

796B Find The Bone的更多相关文章

  1. codeforces 796A-D

    决定在 codeforces 练题啦,决定每个比赛刷前四道...太难就算了 796A Buying A House 题意:给出x轴上的n 个点,每个点有个权值,问离m 点最近的权值小于等于k 的点离m ...

  2. 【codeforces 796B】Find The Bone

    [题目链接]:http://codeforces.com/contest/796/problem/B [题意] 一开始骨头在1号位置; 然后有m个洞,给出洞的下标; 然后有k个交换操作; 如果骨头到洞 ...

  3. 玩儿转物联网IoT - 在Beagle Bone Black上运行node.js 程序

    物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...

  4. Tempter of the Bone

    Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he ...

  5. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  6. hdu–2369 Bone Collector II(01背包变形题)

    题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...

  7. hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. HDU 2602 Bone Collector WA谁来帮忙找找错

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  9. Bone Collector(01背包)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...

随机推荐

  1. 简单自定义UIToolBar

    let item1 = UIBarButtonItem(title: "分享", style: .Plain, target: self, action: nil) let ite ...

  2. C# 监测每个方法的执行次数和占用时间(测试2)

    在Nuget引用 Castle.DynamicProxy 和 Newtonsoft.Json 这个 原文:http://www.cnblogs.com/RicCC/archive/2010/03/15 ...

  3. java的acm输入输出格式+大数语法

    1.类名称必须采用public class Main方式命名 2.多组输入,读取到文件尾 Scanner scan=new Scanner(System.in); while(scan.hasNext ...

  4. Kafka日志及Topic数据清理

    由于项目原因,最近经常碰到Kafka消息队列拥堵的情况.碰到这种情况为了不影响在线系统的正常使用,需要大家手动的清理Kafka Log.但是清理Kafka Log又不能单纯的去删除中间环节产生的日志, ...

  5. centos7 增加虚拟网卡

    确认内核是否有tun模块 # modinfo tun yum install tunctl -y 如果找不到 vim /etc/yum.repos.d/nux-misc.repo [nux-misc] ...

  6. linux下各权限的细分

    PS:有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功能是由Linux内核版本来支持的,不过现在生产绝大部分跑的li ...

  7. 配置 redis 外网访问

    redis采用的安全策略,默认会只准许本地访问 1 2 3 4 5 6 7 8 9 10 通过简单配置,完成允许外网访问 [root@cache01 conf]# egrep "(^bind ...

  8. VSC KeyNote

    [VSC KeyNote] 1.前后跳转. Alt + LeftArrow, Alt + RightArrow 2.缩进问题. vsc默认缩进为4,但js代码里缩进依旧是2. 因为vscode默认启用 ...

  9. js中的arguments对象

    在Javascript中没有函数重载,而arguments对象弥补了这点不足. js函数的参数是一个数组,在参数个数不固定的情况下,只需要给方法传递不同元素个数的数组即可.即使声明函数时没有形式参数, ...

  10. web.xml中<security-constraint>和四种认证类型

    https://blog.csdn.net/lisheng19870305/article/details/40819481 sztc开发中http请求一直发送后无响应,通过soapui定位异常信息为 ...