CF796B Find The Bone
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.
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.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 1000005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-4
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n, m, k;
int h[maxn];
bool fg[maxn]; int main() {
//ios::sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 1; i <= m; i++)rdint(h[i]), fg[h[i]] = 1;
int posbon = 1;
bool flag = 0;
if (fg[posbon]) {
flag = 1;
}
for (int i = 1; i <= k; i++) {
int u, v; rdint(u); rdint(v);
if (flag)continue;
if (u == posbon) {
posbon = v;
}
else if (v == posbon) {
posbon = u;
}
if (fg[posbon]) {
flag = 1;
}
}
cout << posbon << endl;
return 0;
}
CF796B Find The Bone的更多相关文章
- 玩儿转物联网IoT - 在Beagle Bone Black上运行node.js 程序
物联网(IoT)技术方兴未艾,智能手环,智能血压计,智能眼镜甚至智能鞋垫都开始进入我们的生活,各种智能设备层出不穷,世界已经到了一个"人有多大胆,地有多大产"的时代,不玩儿点物联网 ...
- Tempter of the Bone
Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- hdu–2369 Bone Collector II(01背包变形题)
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...
- 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 ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- ZOJ 2110 Tempter of the Bone
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- 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 ...
随机推荐
- Replace Pioneer注册方法
Replace Pioneer注册方法 Replace Pioneer过期后,会弹出一个注册(Registration)窗口,其中有一个试用选项(Trial License),点击Trial Lice ...
- android手势(gesture)
需要实现两个接口,OnTouchListener ,OnGestureListener 在接口方法中实现各种事件 详见:http://www.cnblogs.com/JczmDeveloper/p/3 ...
- windows下启动命令行
1.当前目录打开命令窗口:shift+鼠标右键,然后打开命令窗口 2.查看监听的端口:netstat – ano
- Angular问题02 创建模块失败、 angular-cli名称问题、升级angular-cli
1 创建模块失败 1.1 问题描述 利用 ng g m 模块名 创建新模块时出错 1.2 错误信息 1.3 问题原因 angular-cli 版本出现问题 1.4 解决办法 卸载掉之前使用的 angu ...
- Switch/Case 的穿透性
/*键盘录入1到12 ,对应输出该月份对应的季节 .如果输入的不是1到12,输出提示信息:您输入的数据有误. PS: 春季:3,4,5月份 夏季: 6,7,8月份 秋季: 9,10,11月份 冬季:1 ...
- DPDK内存管理(1)(转)
1 前言 DPDK将利用hugepage预留的物理内存统一的组织管理起来,然后以库的方式对外提供使用的接口.下图展示了DPDK中内存有关的模块的相互关系. rte_eal 是统一 ...
- php学习笔记-超级全局变量
超级全局变量,超级在哪里呢?相对于global类型的变量,超级全局变量的作用域是没有限制的,函数外.函数内.随便一个PHP文件都可以引用超级全局变量.在PHP中有很多超级全局变量, 常用的有_SERV ...
- SingletonPattern(23种设计模式之一)
设计模式六大原则(1):单一职责原则 设计模式六大原则(2):里氏替换原则 设计模式六大原则(3):依赖倒置原则 设计模式六大原则(4):接口隔离原则 设计模式六大原则(5):迪米特法则 设计模式六大 ...
- noi.ac day1t1 candy
传送门 分析 我们知道如果设A,B分别为将两家店从大到小排序之后各自的前缀和,则 Ans=Max{Min{A[i],B[j]}-W*(i+j)}. 为了得到这个Ans我们可以枚举两个数的Min,然后剩 ...
- 999F Cards and Joy
传送门 题目大意 有n个人n*m张牌,每个人分m张牌.每个人有一个自己喜欢的数值,如果他的牌中有x张数值等于这个值则他的高兴度为L[x],求怎样分配牌可以使得所有人的总高兴度最大. 分析 我们发现每一 ...