Description
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.

#include <stdio.h>
#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */
long n,m,k;
long h[1000000];
int main(int argc, char *argv[]) {scanf("%ld%ld%ld",&n,&m,&k);long i,j;long temp;for(i=0;i<m;i++){scanf("%ld",&temp);h[temp]=1;}long temp1,temp2;long qiu=1;int flag=1;if(h[1]){flag=0;}else{for(i=1;i<=k;i++){scanf("%ld%ld",&temp1,&temp2);if((qiu==temp1||qiu==temp2)&&flag)qiu=temp1+temp2-qiu;if(h[qiu]==1)flag=0;}}printf("%ld\n",qiu);return 0;
}

Find The Bone相关推荐

  1. HDU 2602 Bone Collector DP(01背包)

    Bone Collector Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Desc ...

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

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

  3. hdu 2602 Bone Collector

    终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...

  4. Tempter of the Bone(DFS + 奇偶剪枝,好题)

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

  5. hdu 2602 Bone Collector 01背包

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  6. 回溯法+奇偶剪枝——Hdu 1010 Tempter of the Bone

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

  7. HDU Problem 2062 Bone Collector【01背包】

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. Bone Collector

    Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This ...

  9. HD 2602 Bone Collector (0-1背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy's ...

  10. HDU1010 Tempter of the Bone DFS+剪枝

    点击打开链接 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

最新文章

  1. mysql表分区占用存储_MySQL 分区分表应用场景分析和分区中可能遇到的坑点
  2. 为什么 Java 中 1000==1000 为 false ?
  3. [密码学基础][每个信息安全博士生应该知道的52件事][Bristol Cryptography][第34篇]描述攻击离散对数问题的baby-step/Giant-step方法
  4. oppo的sd卡在哪里打开_oppo的sd卡在哪里打开
  5. java+mysql学生学籍后台管理系统源码
  6. java 字符串查找程序_java-如何在JAR文件中搜索字符串
  7. java中extends怎么用_Java 中extends與implements使用方法
  8. 程序员如何内外兼修?
  9. hdu-1711(hash)
  10. 数字孪生数据中心机房,智能 IDC 高阶运维
  11. Oracle中相同字段补充,oracle一次给多表添加相同字段
  12. 软件测试第三章课后习题
  13. [徐培成系列实战课程]-docker篇-前序
  14. HTTP协议和TCP/IP协议与Socket之间的区别
  15. 吐槽一下typora
  16. 基于HTML+CSS+JavaScript技术设计的博客网站(web前端期末大作业)
  17. HTML常用颜色RGB值
  18. 电路基础知识之什么是共模电感/共模信号/差分信号?
  19. ejb3.0会成功吗?java成昨日黄花了?
  20. 基于GLSurfaceView的视频播放器偶现无画面的问题分析

热门文章

  1. python基本随机生成函数_Python学习笔记(三):随机生成函数方法
  2. SQL比oracle卡,对比Oracle与SQL Server
  3. linux 内核 ntfs,Linux大脑 内核 内核编译(NTFS)
  4. 五十九、Vue中的样式绑定
  5. 九十五、轻松搞定Python中的Excel办公自动化系列
  6. 四十一、Vue项目上手 | 用户管理系统 实现用户修改和删除功能(完成篇)
  7. ICLR 2022 | Transformer不比CNN强!Local Attention和动态Depth-wise卷积
  8. LSTM之父重提30年前的「快速权重存储系统」:线性Transformer只是它的一种变体...
  9. NLP Chinese Corpus:大规模中文自然语言处理语料
  10. javaCh6课堂测试