题意:给定一个n个点,m条边的图,其中k个点上有探测器
再给定一个探测器第一次被遍历的序列,问是否存在一种遍历顺序使得满足给定序列且遍历完所有点
这样dfs到的探测器保证了是从当前结点可以不通过任何探测器结点便可以访问的,最后判断一下是否每个节点都被访问过,即 图是否连通
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
//LOOP
#define FF(i, a, b) for(int i = (a); i < (b); ++i)
#define FE(i, a, b) for(int i = (a); i <= (b); ++i)
#define FED(i, b, a) for(int i = (b); i>= (a); --i)
#define REP(i, N) for(int i = 0; i < (N); ++i)
#define CLR(A,value) memset(A,value,sizeof(A))
#define FC(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define PB push_back
//INPUT
#define RI(n) scanf("%d", &n)
#define RII(n, m) scanf("%d%d", &n, &m)
#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)
#define sqr(x) (x) * (x)
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> VI;
const int INF = 0x3f3f3f3f;
const LL lINF = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int maxn = 100010;
int n, m, k;
bool is[maxn], vis[maxn];
VI G[maxn], K;
void init()
{
CLR(is, 0);
CLR(vis, 0);
K.clear();
FE(i, 0, n + 1) G[i].clear();
}
void dfs(int u)
{
vis[u] = 1;
REP(i, G[u].size())
{
int v = G[u][i];
if (vis[v]) continue;
if (is[v])
{
vis[v] = 1;
continue;
}
else
dfs(v);
}
}
int main()
{
int T, x, y;
RI(T);
while (T--)
{
RIII(n, m, k);
init();
REP(i, k)
{
RI(x);
is[x] = 1;
}
REP(i, m)
{
RII(x, y);
G[x].PB(y), G[y].PB(x);
}
int L, flag = 1;
RI(L);
REP(i, L)
{
RI(x);
K.PB(x);
}
if (L < k)
{
flag = 0;
goto end;
}
dfs(K[0]);
FF(i, 1, K.size())
{
if (vis[K[i]])
dfs(K[i]);
else
{
flag = 0;
goto end;
}
}
FE(i, 1, n)
if (!vis[i])
{
flag = 0;
break;
}
end:;
if (flag)
puts("Yes");
else
puts("No");
}
return 0;
}
/*
*/