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.

Input

The first line contains three integers nm, 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 ≤ nui ≠ 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.

题意:骨头在第一个位置,有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的更多相关文章

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

  2. Codeforces Round #408 (Div. 2)C. Bank Hacking(STL)

    题目链接:http://codeforces.com/problemset/problem/796/C 题目大意:有n家银行,第一次可以攻击任意一家银行(能量低于自身),跟被攻击银行相邻或者间接相邻( ...

  3. Codeforces Round #408 (Div. 2) C. Bank Hacking

    http://codeforces.com/contest/796/problem/C Although Inzane successfully found his beloved bone, Zan ...

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

  5. Codeforces Round #408 (Div. 2) D - Police Stations

    地址:http://codeforces.com/contest/796/problem/D 题目: D. Police Stations time limit per test 2 seconds ...

  6. Codeforces Round #408 (Div. 2)

    C. Bank Hacking 题目大意:给出一棵n个节点的树,每个节点有一个权值,删掉一个点的代价为当前这个点的权值,并且会使其相邻点和距离为2且中间隔着未被删除的点的点权值加1,现在选一个点开始删 ...

  7. Codeforces Round #408 (Div. 2) 题解【ABCDE】

    A - Buying A House 题意:给你n个房间,妹子住在第m个房间,你有k块钱,你想买一个离妹子最近的房间.其中相邻的房间之间距离为10,a[i]=0表示已经被别人买了. 题解:扫一遍更新答 ...

  8. Codeforces Round #408 (Div. 2) D. Police Stations(最小生成树+构造)

    传送门 题意 n个点有n-1条边相连,其中有k个特殊点,要求: 删去尽可能多的边使得剩余的点距特殊点的距离不超过d 输出删去的边数和index 分析 比赛的时候想不清楚,看了别人的题解 一道将1个联通 ...

  9. Codeforces Round #408 (Div. 2) C.Bank Hacking(二分)

    传送门 题意 给出n个银行,银行之间总共有n-1条边,定义i与j有边相连为neighboring,i到j,j到k有边,则定义i到k的关系为semi- neighboring, 每家银行hack的难度为 ...

随机推荐

  1. 项目Alpha冲刺(团队9/10)

    项目Alpha冲刺(团队9/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...

  2. hibernate预编译SQL语句中的setParameter和setParameterList

    使用预编译SQL语句和占位符參数(在jdbc中是?),可以避免由于使用字符串拼接sql语句带来的复杂性.我们先来简单的看下.使用预编译SQL语句的优点. 使用String sql = "se ...

  3. ABAP range 用法

    转自http://www.sapjx.com/abap-range-table.html 1. Range Table 概述 Range Table 为 SAP R/3系统标准内表的一种,结构与 Se ...

  4. Intelij Idea 2016.3.4激活

    https://www.haxotron.com/jetbrains-intellij-idea-crack-123/ http://idea.lanyus.com/

  5. javascript中基本类型和引用类型的区别分析

    大多数人系统学习过的程序设计语言,在这些语言的学习过程中最早学到的几个要点之一就是值类型和引用类型的区别.下面我们来看一下在 JavaScript 中基本数据类型(Primitive Types)和引 ...

  6. [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)]

    我自己写的第一个 Silverlight 2.0 程序    [Silverlight 2.0 控制物体绕圆弧运行(C#初探篇)]            程序运行时:小地球将绕着圆形轨迹做圆周运动. ...

  7. CSS:清除浮动

    周五去听css样式的培训,讲到float导致div不能被撑开的问题,特记录如下: 在写HTML代码的时候,如果有一个DIV作为外部容器,内部的DIV如果设置了float样式,则外部的容器DIV因为内部 ...

  8. 一个小bug,关于fuse_mount_sys

    在mount.c  中的 int fuse_mount_sys 函数中,如果注销掉 fd的open语句,此时fd一般为0. 然后,用普通用户运行ssfs且不加-f参数,一切显示正常 fuse_moun ...

  9. 自写程序调用mount

    代码: int fd = open("/dev/fuse", O_RDWR); printf("fd=%d\n",fd); int res; res=mount ...

  10. codeforces 691C C. Exponential notation(科学计数法)

    题目链接: C. Exponential notation time limit per test 2 seconds memory limit per test 256 megabytes inpu ...