A10920 | Find The Bone
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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=u_{i}$ and $x=v_{i}$ . 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.
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=u_{i}$ and $x=v_{i}$ . 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<=10^{6}$ , $1<=m<=n$ , $1<=k<=3·10^{5}$ ) — 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 $h_{1},h_{2},...,h_{m}$ ( $1<=h_{i}<=n$ ) — the positions along the $x$ -axis where there is a hole on the table.
Each of the next $k$ lines contains two integers $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ , $u_{i}≠v_{i}$ ) — the positions of the cups to be swapped.
The second line contains $m$ distinct integers $h_{1},h_{2},...,h_{m}$ ( $1<=h_{i}<=n$ ) — the positions along the $x$ -axis where there is a hole on the table.
Each of the next $k$ lines contains two integers $u_{i}$ and $v_{i}$ ( $1<=u_{i},v_{i}<=n$ , $u_{i}≠v_{i}$ ) — the positions of the cups to be swapped.
输出格式
Print one integer — the final position along the $x$ -axis of the bone.
输入输出样例
输入 #1
7 3 4 3 4 6 1 2 2 5 5 7 7 1
输出 #1
1
输入 #2
5 1 2 2 1 2 2 4
输出 #2
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.
In the second sample, after the first operation, the bone becomes at $x=2$ , and falls into the hole onto the ground.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted