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. @JsonInclude注解,RestTemplate传输值为null的属性,利用FastJson将属性中有空值null的对象转化成Json字符串

    一个pojo类: import lombok.Data; @Data public class Friend { private String name; private int age; priva ...

  2. php首字母 大写 数组去重复

    $zimu[]=strtoupper(substr( $value['title'], 0, 1 ));//大写 $zimu[]=strtolower(substr( $value['title'], ...

  3. linux中weblogic相关命令操作

    在weblogic的目录下找到bin目录,其中有startWeblogic.sh.startManagerWeblogic.sh等 首先需要启动startWeblogic.sh,这个是管理服务,也就是 ...

  4. python3获得命令行输入的参数

    外部直接执行python文件时,我们有时需要获得命令行的参数   获得命令行参数的两种方式   1.通过sys.argv sys.argv:获得一个参数列表,第一个值为文件名本身,通过sys.argv ...

  5. centos7.4上安装python3环境的坑

    前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...

  6. Android设置ScrollView回到顶部的三种方式 (转)

    一.ScrollView.scrollTo(0,0)  直接置顶,瞬间回到顶部,没有滚动过程,其中Y值可以设置为大于0的值,使Scrollview停在指定位置; 二.ScrollView.fullSc ...

  7. thymeleaf 获取sessionid

    参考https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html ${#session.id}

  8. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  9. Java项目--俄罗斯方块

    Java项目--俄罗斯方块 百度盘链接 链接:http://pan.baidu.com/s/1mhQ9SYc 密码:9ujo 一.心得 二.游戏实例 游戏截图 目录结构 三.代码 1.主界面 Tetr ...

  10. pep8 && pep20

    pep8(部分,遇到问题再补充) 1.不建议使用tab键来空格,避免不必要的空格.操作符左右各加一个空格,函数默认参数使用的赋值符左右省略空格. 2.类和top-level函数定义之间空两行:类中的方 ...