ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
Description
Edward is a rich man. He owns a large factory for health drink production. As a matter of course, there is a large warehouse in the factory.
To ensure the safety of drinks, Edward hired a security man to patrol the warehouse. The warehouse has N piles of drinks and M passageways connected them (warehouse is not big enough). When the evening comes, the security man will start to patrol the warehouse following a path to check all piles of drinks.
Unfortunately, Edward is a suspicious man, so he sets sensors on K piles of the drinks. When the security man comes to check the drinks, the sensor will record a message. Because of the memory limit, the sensors can only record for the first time of the security man's visit.
After a peaceful evening, Edward gathered all messages ordered by recording time. He wants to know whether is possible that the security man has checked all piles of drinks. Can you help him?
The security man may start to patrol at any piles of drinks. It is guaranteed that the sensors work properly. However, Edward thinks the security man may not works as expected. For example, he may digs through walls, climb over piles, use some black magic to teleport to anywhere and so on.
Input
There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
The first line contains three integers N (1 <= N <= 100000), M (1 <= M <= 200000) and K (1 <= K <= N).
The next line contains K distinct integers indicating the indexes of piles (1-based) that have sensors installed. The following M lines, each line contains two integers Ai and Bi (1 <= Ai, Bi <= N) which indicates a bidirectional passageway connects piles Ai and Bi.
Then, there is an integer L (1 <= L <= K) indicating the number of messages gathered from all sensors. The next line contains L distinct integers. These are the indexes of piles where the messages came from (each is among the K integers above), ordered by recording time.
Output
For each test case, output "Yes" if the security man worked normally and has checked all piles of drinks, or "No" if not.
Sample Input
2
5 5 3
1 2 4
1 2
2 3
3 1
1 4
4 5
3
4 2 1
5 5 3
1 2 4
1 2
2 3
3 1
1 4
4 5
3
4 1 2
Sample Output
No
Yes
Source
/*
* Author: Joshua
* Created Time: 2014年09月09日 星期二 17时27分53秒
* File Name: zoj3811.cpp
*/
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std; #define maxn 100005 typedef long long LL;
int f[maxn],n,m,k,T;
bool p[maxn];
vector<int> r[maxn]; void init()
{
int l,v,u,x,y;
memset(p,,sizeof(p));
scanf("%d%d%d",&n,&m,&k);
for (int i=;i<=k;++i)
{
scanf("%d",&x);
p[x]=true;
}
for (int i=;i<=n;++i) r[i].clear();
for (int i=;i<=m;++i)
{
scanf("%d%d",&u,&v);
r[u].push_back(v);
r[v].push_back(u);
}
for (int i=;i<=n;++i) f[i]=i;
} int gf(int x)
{
if (f[x]==x) return x;
return (f[x]=gf(f[x]));
} void update(int x)
{
int fx,fy;
for (int j=;j<r[x].size();++j)
if (!p[r[x][j]])
{
fx=gf(x);
fy=gf(r[x][j]);
if (fx<fy) f[fy]=fx;
else f[fx]=fy;
}
} void solve()
{
int l,x,y;
scanf("%d",&l);
if (l!=k)
{
for (int i=;i<=l;++i)
scanf("%d",&x);
printf("No\n");
return;
}
for (int i=;i<=n;++i)
if (!p[i])
update(i);
for (int i=;i<=l;++i)
{
scanf("%d",&x);
p[x]=false;
update(x);
if ((i>) && (gf(x)!=gf(y)))
{
printf("No\n");
for (int j=i+;j<=l;++j) scanf("%d",&x);
return;
}
y=x;
}
for (int i=;i<=n;++i)
if (gf(i)!=)
{
printf("No\n");
return;
}
printf("Yes\n");
}
int main()
{
scanf("%d",&T);
while (T--)
{
init();
solve();
}
return ;
}
ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round的更多相关文章
- zoj 3811 Untrusted Patrol(bfs或dfs)
Untrusted Patrol Time Limit: 3 Seconds Memory Limit: 65536 KB Edward is a rich man. He owns a l ...
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP
Clone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) Total Submiss ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C
题意: 这个是The 2014 ACM-ICPC Asia Mudanjiang Regional First Round 的C题,这个题目当时自己想的很复杂,想的是优先队列广搜,然后再在 ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
The Himalayas http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5341 签到 #include<cstdio& ...
- ZOJ 3811 Untrusted Patrol
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3811 解题报告:一个无向图上有n个点和m条边,其中有k个点上安装 ...
- ZOJ 3811 Untrusted Patrol【并查集】
题目大意:给一个无向图,有些点有装监视器记录第一次到达该点的位置,问是否存在一条路径使得监视器以给定的顺序响起,并且经过所有点 思路:牡丹江网络赛的题,当时想了种并查集的做法,通神写完程序WA了几发, ...
- HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...
- 2014 ACM/ICPC Asia Regional Shanghai Online
Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...
随机推荐
- 51nod_1417:天堂里的游戏
题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1417 假设 ans=n/m,C=(A+B)/2 若出正面 ...
- 浮点数的陷阱--double i != 10 基本都是对的,不管怎么赋值
#include <stdio.h>int main(){ double i; for(i = 10; i != 10, i < 12; i += 0.1) ...
- 【tomcat8】consider increasing the maximum size of the cache
[/WEB-INF/classes/hudson/model/Messages_zh_CN.properties] to the cache for web application [/jenkins ...
- [C++ Calculator 项目] 基础运算实现
Calculator V1.1 注:这是C++计算器项目第二部分-运算 [基于初始部分增改而得] 源文件已上传至github 主要问题: Ⅰ.运算实现的问题在于( ) + - * /的优先级的处理,以 ...
- 【TRICK】解决锚点定位向下浮动Xpx问题
1. 问题描述 页面滚动后,菜单栏会固定在页头,当锚点定位时,菜单会遮盖部分定位后的内容,所以需要在锚点定位后自动向下漂移Xpx. 2. 解决办法 a. 利用空div 占位,如下: <a hre ...
- ubuntu上安装nginx+mysql+php5-fpm(PHP5 - FastCGI Process Manager)
题外话:由于近段时间测试环境ssh链路质量不大好,经常短线.故我把整个安装过程放到screen里去执行,以防止断线中断了安装过程.执行screen -S install,这样断线后,只要再执行scre ...
- [COGS 1065] 绿豆蛙的归宿
先贴题面w 1065. [Nescafe19] 绿豆蛙的归宿 ★ 输入文件:ldfrog.in 输出文件:ldfrog.out 简单对比时间限制:1 s 内存限制:128 MB 随着新 ...
- git bash命令行使用https协议方式进行克隆和提交到github服务器
在本地创建一个文件夹来存放远程服务器仓库:如创建一个git8文件夹: 在命令行中,使用git clone https://github.com/serverking/weixin.git进行克隆git ...
- ASP.NET windows验证IIS配置
Windows验证时,需要配置IIS,把匿名验证设为disable,windows验证设为enable,window7 默认为匿名验证为enable,windows验证为disable. 否则会sys ...
- 【NO.8】jmeter-场景-上传文件-send-a-file
简要说就3点: POST请求 Request的参数都写在路径内,不写在表单里 上传的文件写在表单里 只要记住以上3点,也就避免了在设计脚本的时候走弯路.下面具体图文并茂地介绍如何使用Jmeter实现上 ...