Codeforces Round #408 (Div. 2) B
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 = 5at 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.
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.
Print one integer — the final position along the x-axis of the bone.
7 3 4
3 4 6
1 2
2 5
5 7
7 1
1
5 1 2
2
1 2
2 4
2
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.
题意:骨头在第一个位置,有hi个洞,我们进行移动操作,如果骨头掉入洞里就输出洞的位置,否则按照移动的最后结果输出
解法:首先骨头在第一个位置,如果第一个位置有洞则直接输出,否则模拟移动操作,当然有些移动操作对结果没有影响
直到进洞或者移动结束
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,int>q;
int n,m,k;
int main()
{
std::ios::sync_with_stdio(false);
cin>>n>>m>>k;
for(int i=;i<=m;i++)
{
int num;
cin>>num;
q[num]=;
}
if(q[])
{
cout<<""<<endl;
return ;
}
int ans=;
for(int i=;i<=k;i++)
{
int v,u;
cin>>v>>u;
if(v!=ans&&u!=ans) continue;
if(q[ans])
{
cout<<ans<<endl;
return ;
}
else if(v==ans)
{
swap(v,u);
ans=v;
}
else if(u==ans)
{
swap(v,u);
ans=u;
}
}
cout<<ans<<endl;
return ;
}
Codeforces Round #408 (Div. 2) B的更多相关文章
- Codeforces Round #408 (Div. 2)(A.水,B,模拟)
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #408 (Div. 2)C. Bank Hacking(STL)
题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻( ...
- Codeforces Round #408 (Div. 2) C. Bank Hacking
http://codeforces.com/contest/796/problem/C Although Inzane successfully found his beloved bone, Zan ...
- Codeforces Round #408 (Div. 2) A B C 模拟 模拟 set
A. Buying A House time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #408 (Div. 2) D - Police Stations
地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...
- Codeforces Round #408 (Div. 2)
C. Bank Hacking 题目大意:给出一棵n个节点的树,每个节点有一个权值,删掉一个点的代价为当前这个点的权值,并且会使其相邻点和距离为2且中间隔着未被删除的点的点权值加1,现在选一个点开始删 ...
- Codeforces Round #408 (Div. 2) 题解【ABCDE】
A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答 ...
- Codeforces Round #408 (Div. 2) D. Police Stations(最小生成树+构造)
传送门 题意 n个点有n-1条边相连,其中有k个特殊点,要求: 删去尽可能多的边使得剩余的点距特殊点的距离不超过d 输出删去的边数和index 分析 比赛的时候想不清楚,看了别人的题解 一道将1个联通 ...
- Codeforces Round #408 (Div. 2) C.Bank Hacking(二分)
传送门 题意 给出n个银行,银行之间总共有n-1条边,定义i与j有边相连为neighboring,i到j,j到k有边,则定义i到k的关系为semi- neighboring, 每家银行hack的难度为 ...
随机推荐
- EF中 Code-First 方式的数据库迁移
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/code-first-migrations-with-entity-framework/ 系列目 ...
- hadoop yarn namenode datanoe 启动异常问题解决 分析日志
cat logs/hadoop-root-datanode-hadoop1.log ********************************************************** ...
- group by where having 联合使用
having子句与where有相似之处但也有区别,都是设定条件的语句.在查询过程中聚合语句(sum,min,max,avg,count)要比having子句优先执行.而where子句在查询过程中执行优 ...
- NEU 1685: All Pair Shortest Path
题目描述 Bobo has a directed graph G with n vertex labeled by 1,2,3,..n. Let D(i,j) be the number of edg ...
- i2c_set_clientdata函数【转】
本文转载自‘:http://blog.csdn.net/jk198310/article/details/43738367 在i2c驱动中有很多函数和数据结构,很多一时难以理解,所以写下本文共同学习. ...
- SDUT OJ 2054 双向链表的实现 (结构体node指针+遍历 *【模板】)
双向链表 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 学会了单向链表,我们又多了一种解决问题的能力,单链表利用一个指针就能在内 ...
- dedecms获取顶级栏目名称、二级栏目名称实现方法
织梦DEDECMS文章.栏目页获取当前页面顶级栏目名称的方法 在用织梦做一些项目时,时常会碰到需要在当前页面调用顶级栏目名称的时候,织梦默认{dede:field name='typename' /} ...
- Android 代码设置RelativeLayout元素居中
RelativeLayout relativeLayout= new RelativeLayout(this); RelativeLayout.LayoutParams rlp=new Relativ ...
- async-await原理解析
在用async包裹的方法体中,可以使用await关键字以同步的方式编写异步调用的代码.那么它的内部实现原理是什么样的呢?我们是否可以自定义await以实现定制性的需求呢?先来看一个简单的例子: cla ...
- [Selenium] 操作浏览器 Cookies
WebDriver 提供了一系列 Cookies 的操作来获取.填写.删除 Cookies 的方法,节省了多次在登陆页面的查找元素并填写登录信息的时间. 1)获取 Cookies ,并保存到文件中以备 ...