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

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

The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
 
 
题意:给出n个点,m条边,在其中k个点上有传感器,有一个人在图上走。再给出长度为l的序列,为传感器第一次感知有人走到的顺序。求该人的行走是否合法且遍历全图。
思路:设没有传感器的点为普通点,有传感器的点为特殊点。先把普通点加入并查集中。然后按照l序列的顺序,把特殊点变为普通点,然后加入并查集。判断该点和之前的一个点是否联通,不联通则违法。注意还有两个要特判,l不等于k以及整张图不是联通图,这两种情况都要输出no。
 /*
* 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的更多相关文章

  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. CAP 介绍及使用【视频】

    前言 很多同学可能对于CAP这个项目想有更一步的了解,包括她的工作原理以及适用的场景,所以博主就准备了一场直播给他家讲解了一下,这个视频是直播的一个录像. 由于我这次直播本来是没有打算对外的,所以也是 ...

  2. LINUX下的远端主机登入 校园网络注册 网络数据包转发和捕获

    第一部分:LINUX 下的远端主机登入和校园网注册 校园网内目的主机远程管理登入程序 本程序为校园网内远程登入,管理功能,该程序分服务器端和客户端两部分:服务器端为remote_server_udp. ...

  3. JavaScript系统学习小结——变量、作用域和内存问题

    趁着写完小论文还未彻底消散的学习氛围,开始着重巩固自己JavaScript的基础知识,为秋招做最基本的准备. 变量:Js的变量可能保存两种不同数据类型的值:基本类型值和引用类型值. 基本类型包括:Un ...

  4. MySQL学习笔记(六):索引

    本文主要介绍MySQL 中关于索引的一些问题,例如:索引的作用:怎么创建索引:设计索引的原则:怎么优化索引等等. 一:索引概述 索引一般是通过排序,然后查找时可以二分查找,这一特点来达到加速查找的目的 ...

  5. python-继承类执行的流程

    在读python数据机构与算法, 发现了下面这个例子, 之前没有碰到过, 记录下来 In [17]: class A: def f(self): self.g() def g(self): print ...

  6. java亦或(^)

    在java程序里面的异或用法: 相同输出0,不同输出1,例如: System.out.println(1^1); 输出0 System.out.println(1^2):输出3,因为最后2个低位都不一 ...

  7. Aspose.Words关于域的应用

    #region 通过word域去插入相应的数据 /// <summary> /// 通过word域去进行指定位置替换数据 /// </summary> public void ...

  8. Head First 设计模式 第3章 装饰者模式

    第3章 装饰者模式 1.定义/说明 动态.透明的将职责附加到对象上(或从对象上撤销),而不影响其他对象.若要扩展功能,装饰者模式提供了比继承更富有弹性的替代方案. 2.介绍 首先让我们先来介绍一下场景 ...

  9. NYOJ 23.取石子(一)

    取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游 ...

  10. Loadrunner分布式测试

    据经验,每生成一个虚拟用户,需要花费负载生成器大约 2M-3M 的内存空间.通常运行 controller的主机很少用作负载生成器.负载生成器的工作多由其他装有 LR Agent的PC 机来担任.如果 ...