-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathE.cpp
More file actions
69 lines (67 loc) · 1.43 KB
/
E.cpp
File metadata and controls
69 lines (67 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
using namespace std;
int const N = 2e5 + 5;
vector< vector<int> > adj(N);
int in[N], out[N], cur = 0;
int prt[N], depth[N];
void dfs(int u){
in[u] = cur++;
for(int v: adj[u]){
if(v == prt[u]) continue;
prt[v] = u;
depth[v] = depth[u] + 1;
dfs(v);
}
out[u] = cur++;
}
bool is_parent(int u, int v){
return in[u] < in[v] && out[u] > out[v];
}
int main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false), cin.tie(0),cout.tie(0);
#endif
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int n, q;
cin>>n>>q;
for(int i=0; i<n-1; i++){
int u, v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1);
while(q--){
int k;
cin>>k;
int v[k];
int x, mx = -1;
for(int i=0; i<k; i++){
cin >> v[i];
if(depth[v[i]] > mx){
mx = depth[v[i]];
x = v[i];
}
}
bool ans = true;
for(int i=0; i<k; i++){
if(v[i] == 1 || v[i] == x) continue;
v[i] = prt[v[i]];
if(!is_parent(v[i], x)){
ans = false;
break;
}
}
if(ans)
cout<<"YES\n";
else
cout<<"NO\n";
}
}