ZOJ 3811 Untrusted Patrol
来源:互联网 发布:淘宝怎么联系卖家 编辑:程序博客网 时间:2024/05/16 18:29
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
25 5 31 2 41 22 33 11 44 534 2 15 5 31 2 41 22 33 11 44 534 1 2
Sample Output
NoYes
Author: DAI, Longao
Source: The 2014 ACM-ICPC Asia Mudanjiang Regional First Round
#include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <stdexcept>#include <functional>#include <utility>#include <ctime>using namespace std;#define PB push_back#define MP make_pair#define REP(i,n) for(int i=0;i<(n);++i)#define FOR(i,l,h) for(int i=(l);i<=(h);++i)#define DWN(i,h,l) for(int i=(h);i>=(l);--i)#define CLR(vis,pos) memset(vis,pos,sizeof(vis))#define PI acos(-1.0)#define INF 0x7FFFFFFF#define LINF 1000000000000000000LL#define eps 1e-8typedef long long ll;int scan(){ char c; while(c=getchar(),(c<'0'||c>'9')&&(c!='-')); bool flag=(c=='-'); if(flag) c=getchar(); int x=0; while(c>='0'&&c<='9') { x=x*10+c-48; c=getchar(); } return flag?-x:x;}const int mn=100000+100;int n,m,k;int a[mn],c[mn];int vis[mn];vector<int> p[mn];int ans,cnt;void dfs(int x){ REP(i,p[x].size()) { int v=p[x][i] ; if(vis[v]==0) { if(a[v]==1) { cnt++; ans++; a[v]=0,vis[v]=1; } else { cnt++; vis[v]=1; dfs(v); } } }}int main(){ int T; cin>>T; while(T--) { CLR(a,0),CLR(vis,0); n=scan(),m=scan(),k=scan(); FOR(i,0,n) p[i].clear(); REP(i,k) a[scan()]=1; int u,v; REP(i,m) { u=scan(),v=scan(); p[u].PB(v); p[v].PB(u); } int t; t=scan(); REP(i,t) c[i]=scan(); if(t<k) printf("No\n"); else { a[c[0]]=0,vis[c[0]]=1; cnt=1,ans=1; REP(i,t) { if(a[c[i]]==1) break; dfs(c[i]); } if(cnt==n && ans==t) printf("Yes\n"); else printf("No\n"); } } return 0;}
- ZOJ 3811 Untrusted Patrol
- ZOJ 3811 Untrusted Patrol
- ZOJ 3811-Untrusted Patrol(DFS)
- ZOJ 3811 Untrusted Patrol(BFS)
- ZOJ 3811 Untrusted Patrol 并查集
- Zoj 3811 Untrusted Patrol 求连通顺序
- ZOJ 3811 Untrusted Patrol 标记+dfs
- ZOJ-3811-Untrusted Patrol 解题报告
- ZOJ 3811 Untrusted Patrol 并查集
- ZOJ 3811——Untrusted Patrol
- zoj 3811 Untrusted Patrol DFS SET
- ZOJ Problem Set - 3811 Untrusted Patrol
- ZOJ Problem Set - 3811 Untrusted Patrol
- 2014网络赛第一场 Untrusted Patrol ZOJ-3811
- ZOJ 3811 Untrusted Patrol(dfs+并查集)
- ZOJ 3811 / 2014 牡丹江赛区网络赛 C. Untrusted Patrol
- ZOJ 3811 Untrusted Patrol 并查集 染色 BFS
- zoj 3811 Untrusted Patrol(邻接表并查集)
- Unable to find a java Virtual Machine ---- Oracle Developer
- 粉碎在选矿过程中起到的作用
- spring Mvc 教程框架实例以及系统演示下载-转载自coding云
- Android消息推送机制
- Spring3.x--自动检测Bean
- ZOJ 3811 Untrusted Patrol
- 选矿中破碎作业的划分
- 线性感知器(对Andrew讲义的理解)
- STM32
- javascript字符串去空格的几种方法
- 共享内存,多进程间共享结构体
- 选矿常见的破碎方法
- sql 脚本 临时表删除
- Ajax以post方式提交数据