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 <= AiBi <= 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

  1. 2
  2. 5 5 3
  3. 1 2 4
  4. 1 2
  5. 2 3
  6. 3 1
  7. 1 4
  8. 4 5
  9. 3
  10. 4 2 1
  11. 5 5 3
  12. 1 2 4
  13. 1 2
  14. 2 3
  15. 3 1
  16. 1 4
  17. 4 5
  18. 3
  19. 4 1 2

Sample Output

  1. No
  2. Yes

Source

The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
 
 
题意:给出n个点,m条边,在其中k个点上有传感器,有一个人在图上走。再给出长度为l的序列,为传感器第一次感知有人走到的顺序。求该人的行走是否合法且遍历全图。
思路:设没有传感器的点为普通点,有传感器的点为特殊点。先把普通点加入并查集中。然后按照l序列的顺序,把特殊点变为普通点,然后加入并查集。判断该点和之前的一个点是否联通,不联通则违法。注意还有两个要特判,l不等于k以及整张图不是联通图,这两种情况都要输出no。
  1. /*
  2. * Author: Joshua
  3. * Created Time: 2014年09月09日 星期二 17时27分53秒
  4. * File Name: zoj3811.cpp
  5. */
  6. #include<cstdio>
  7. #include<vector>
  8. #include<cstring>
  9. using namespace std;
  10.  
  11. #define maxn 100005
  12.  
  13. typedef long long LL;
  14. int f[maxn],n,m,k,T;
  15. bool p[maxn];
  16. vector<int> r[maxn];
  17.  
  18. void init()
  19. {
  20. int l,v,u,x,y;
  21. memset(p,,sizeof(p));
  22. scanf("%d%d%d",&n,&m,&k);
  23. for (int i=;i<=k;++i)
  24. {
  25. scanf("%d",&x);
  26. p[x]=true;
  27. }
  28. for (int i=;i<=n;++i) r[i].clear();
  29. for (int i=;i<=m;++i)
  30. {
  31. scanf("%d%d",&u,&v);
  32. r[u].push_back(v);
  33. r[v].push_back(u);
  34. }
  35. for (int i=;i<=n;++i) f[i]=i;
  36. }
  37.  
  38. int gf(int x)
  39. {
  40. if (f[x]==x) return x;
  41. return (f[x]=gf(f[x]));
  42. }
  43.  
  44. void update(int x)
  45. {
  46. int fx,fy;
  47. for (int j=;j<r[x].size();++j)
  48. if (!p[r[x][j]])
  49. {
  50. fx=gf(x);
  51. fy=gf(r[x][j]);
  52. if (fx<fy) f[fy]=fx;
  53. else f[fx]=fy;
  54. }
  55. }
  56.  
  57. void solve()
  58. {
  59. int l,x,y;
  60. scanf("%d",&l);
  61. if (l!=k)
  62. {
  63. for (int i=;i<=l;++i)
  64. scanf("%d",&x);
  65. printf("No\n");
  66. return;
  67. }
  68. for (int i=;i<=n;++i)
  69. if (!p[i])
  70. update(i);
  71. for (int i=;i<=l;++i)
  72. {
  73. scanf("%d",&x);
  74. p[x]=false;
  75. update(x);
  76. if ((i>) && (gf(x)!=gf(y)))
  77. {
  78. printf("No\n");
  79. for (int j=i+;j<=l;++j) scanf("%d",&x);
  80. return;
  81. }
  82. y=x;
  83. }
  84. for (int i=;i<=n;++i)
  85. if (gf(i)!=)
  86. {
  87. printf("No\n");
  88. return;
  89. }
  90. printf("Yes\n");
  91. }
  92. int main()
  93. {
  94. scanf("%d",&T);
  95. while (T--)
  96. {
  97. init();
  98. solve();
  99. }
  100. return ;
  101. }

ZOJ 3811 Untrusted Patrol The 2014 ACM-ICPC Asia Mudanjiang Regional First Round的更多相关文章

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

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

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

  4. The 2014 ACM-ICPC Asia Mudanjiang Regional First Round C

    题意:       这个是The 2014 ACM-ICPC Asia Mudanjiang Regional First Round 的C题,这个题目当时自己想的很复杂,想的是优先队列广搜,然后再在 ...

  5. The 2014 ACM-ICPC Asia Mudanjiang Regional First Round

    The Himalayas http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5341 签到 #include<cstdio& ...

  6. ZOJ 3811 Untrusted Patrol

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3811 解题报告:一个无向图上有n个点和m条边,其中有k个点上安装 ...

  7. ZOJ 3811 Untrusted Patrol【并查集】

    题目大意:给一个无向图,有些点有装监视器记录第一次到达该点的位置,问是否存在一条路径使得监视器以给定的顺序响起,并且经过所有点 思路:牡丹江网络赛的题,当时想了种并查集的做法,通神写完程序WA了几发, ...

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

  9. 2014 ACM/ICPC Asia Regional Shanghai Online

    Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...

随机推荐

  1. 配置ssh免密码登录——集群学习日记

    度过了难熬的考试月时期之后,最近和小伙伴一起参加的的比赛进入了紧张的准备时期.在进行工作的时候,发现有很多基础的知识点,自己不是很清楚以及了解,所以在想,要不就边学习的时候边写下学习日记,以供自己后来 ...

  2. 第一章:火狐浏览器 : 环境配置: FireFox 版本38 + jdk 7 + selenium 2.53.6 + selenum-version 2.48.2

    配置一套完整的 selenium + Java + Firefox38  环境: 1. 火狐浏览器的版本 : 38 2. JDK 安装 1.7 版本的 3. 安装 Python 的版本是 2.7 4. ...

  3. (转)maven镜像路径配置

    很多maven包无法自动下载怎么办?设置maven镜像setting.xml <mirror> <id>repo2</id> <mirrorOf>cen ...

  4. iOS 使用 socket 即时通信(非第三方库)

    其实写这个socket一开始我是拒绝的. 因为大家学C 语言和linux基础时肯定都有接触,客户端和服务端的通信也都了解过,加上现在很多开放的第三方库都不需要我们来操作底层的通信. 但是来了!!! 但 ...

  5. nopcommerce 开源商城

    http://www.nopchina.net/  中文网 http://www.nopcommerce.com/downloads.aspx  源码下载  如果要在数据库中添加一个新的数据表,需要按 ...

  6. 亚马逊AWS EC2云实例AMI安装LNMP环境(1)——Nginx安装

    概括:这里选择亚马逊EC2的Linux AMI实例,该Linux服务器是亚马逊预配置的Linux环境,内置多个YUM源,属于亚马逊首推的稳定Linux服务器.默认登录用户名为ec2-user,执行ro ...

  7. Nginx配置抵御DDOS或CC攻击

    防攻击的思路我们都明白,比如限制IP啊,过滤攻击字符串啊,识别攻击指纹啦.可是要如何去实现它呢?用守护脚本吗?用PHP在外面包一层过滤?还是直接加防火墙吗?这些都是防御手段.不过本文将要介绍的是直接通 ...

  8. An internal error occurred during: "Launching web on MyEclipse Tomcat"

    An internal error occurred during: "Launching web on MyEclipse Tomcat" 解决办法1 1.首先关闭MyEclip ...

  9. FastDFS安装和配置,整合Nginx-1.13.3

    目录: 一:下载FastDFS  二:安装FastDFS 三:配置 四:整合Nginx和FastDFS FastDFS is an open source high performance distr ...

  10. 生成二维码的js以及调用打印插件

    插件: qrcode.js 插件下载网址:http://code.ciaoca.com/javascript/qrcode/ 用法实例: <script type="text/java ...