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++交,综合以上的条件 ...
随机推荐
- JMeter 之Synchronizing Timer运行原理
JMeter测试并发场景,是通过设置Synchronizing Timer(同步定时器),熟悉LoadRunner性能测试的话,就知道里面有个概念:集合点. Synchronizing Timer则可 ...
- Go的基本环境配置
参考 https://golang.org/doc/install?download=go1.7.1.linux-amd64.tar.gz https://github.com/qlshine/the ...
- 31. leetcode 122. Best Time to Buy and Sell Stock II
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...
- vsftp虚拟主机
################################Vsftp服务器实战##########################################3 文件传输协议,基于该协议FT ...
- 页面发送请求到后台报错“Empty or invalid anti forgery header token.”问题解决
在页面向后台发送请求时,报如上图的错误的解决办法: 在WebModule.cs类中的PreInitialize方法中加 Configuration.Modules.AbpWeb().AntiForge ...
- java大数取余
java大数取余: 类方法:BigInteger.divideAndRemainder() 返回一个数组,key = 0为商key = 1为余数 import java.util.*; import ...
- SSE图像算法优化系列十:简单的一个肤色检测算法的SSE优化。
在很多场合需要高效率的肤色检测代码,本人常用的一个C++版本的代码如下所示: void IM_GetRoughSkinRegion(unsigned char *Src, unsigned char ...
- Java String字符串深入详解
Java中字符串对象创建有两种形式,一种为字面量形式,如String str = "hello";,另一种就是使用new这种标准的构造对象的方法,如String str = new ...
- 实用css小技巧
display应用 在取消了ul/ol的默认样式{padding:0;list-style-type:none;}的时候:ul的li设置成了行内块(display:inline-block)的话,这时 ...
- ASP.NET Core身份验证服务框架IdentityServer4-整体介绍
一.整体情况 现代应用程序看起来更像这个: 最常见的相互作用: 浏览器与Web应用程序的通信 Browser -> Web App Web应用程序与Web API通信 基于浏览器的应用程序与We ...