#include <bits/stdc++.h>
using namespace std;
int pr[120001],dep[120001],vis[120001],deg[1001];
vector<int> adj[120001],tree[1001];
void dfs(int i,int ppp){
pr[i] = ppp;
dep[i] = dep[ppp]+1;
for(auto j:adj[i]){
if(j==ppp)continue;
dfs(j,i);
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;cin>>t;
z:while(t--){
int n;cin>>n;
for(int i = 1;i<=n;i++){
adj[i].clear();
pr[i] = 0 , dep[i] = 0;
vis[i] = 0;
}
for(int i = 1;i<n;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,0);
int q;cin>>q;
vector<pair<int,int>> qu;
for(int i = 1;i<=q;i++){
int a,b;
cin>>a>>b;
qu.push_back({a,b});
}
for(int i = 1;i<=q;i++){
deg[i] = 0 ;tree[i].clear();
}
for(int i = 0;i<qu.size();i++){
int x = qu[i].first , y = qu[i].second;
while(x!=y){
if(dep[x]<dep[y])swap(x,y);
vis[x] = i+1;
x = pr[x];
}
vis[x] = i+1;
for(int j = 0;j<qu.size();j++){
if(i==j)continue;
if(vis[qu[j].first]==i+1&&vis[qu[j].second]==i+1){
cout<<"No\n";
goto z;
}
if(vis[qu[j].first]==i+1){
tree[i+1].push_back(j+1);
deg[j+1]++;
}else if(vis[qu[j].second]==i+1){
tree[j+1].push_back(i+1);
deg[i+1]++;
}
}
}
int cnt = 0;queue<int> qe;
for(int i = 1;i<=q;i++){
if(deg[i]==0){
qe.push(i);
}
}
while(!qe.empty()){
int x = qe.front();qe.pop();
cnt++;
for(auto j:tree[x]){
deg[j]--;
if(deg[j]==0){
qe.push(j);
}
}
}
if(cnt==q)cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0;i<qu.size();i++){
| ~^~~~~~~~~~
jail.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j = 0;j<qu.size();j++){
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3324 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
6 ms |
3164 KB |
Output is correct |
5 |
Correct |
13 ms |
4080 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3416 KB |
Output is correct |
9 |
Correct |
34 ms |
6300 KB |
Output is correct |
10 |
Correct |
165 ms |
16724 KB |
Output is correct |
11 |
Correct |
4 ms |
3416 KB |
Output is correct |
12 |
Correct |
17 ms |
4084 KB |
Output is correct |
13 |
Runtime error |
112 ms |
31432 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
2 ms |
3368 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3316 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
2 ms |
3368 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3316 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3160 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
2 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3316 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
3368 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3368 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
2 ms |
3368 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3316 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3160 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
2 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3316 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
3368 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3368 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3320 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
3164 KB |
Output is correct |
33 |
Correct |
2 ms |
3160 KB |
Output is correct |
34 |
Correct |
2 ms |
3160 KB |
Output is correct |
35 |
Correct |
2 ms |
3416 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
3 ms |
3164 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
2 ms |
3368 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3316 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3160 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
2 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3316 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
2 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
2 ms |
3368 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3368 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
2 ms |
3320 KB |
Output is correct |
29 |
Correct |
2 ms |
3420 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
3164 KB |
Output is correct |
33 |
Correct |
2 ms |
3160 KB |
Output is correct |
34 |
Correct |
2 ms |
3160 KB |
Output is correct |
35 |
Correct |
2 ms |
3416 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
2 ms |
3164 KB |
Output is correct |
38 |
Correct |
34 ms |
6428 KB |
Output is correct |
39 |
Correct |
167 ms |
16676 KB |
Output is correct |
40 |
Correct |
21 ms |
4780 KB |
Output is correct |
41 |
Correct |
24 ms |
4596 KB |
Output is correct |
42 |
Correct |
19 ms |
4948 KB |
Output is correct |
43 |
Correct |
17 ms |
4688 KB |
Output is correct |
44 |
Correct |
10 ms |
3676 KB |
Output is correct |
45 |
Correct |
38 ms |
9720 KB |
Output is correct |
46 |
Correct |
30 ms |
9916 KB |
Output is correct |
47 |
Correct |
50 ms |
12696 KB |
Output is correct |
48 |
Correct |
51 ms |
12636 KB |
Output is correct |
49 |
Correct |
28 ms |
9808 KB |
Output is correct |
50 |
Correct |
32 ms |
10040 KB |
Output is correct |
51 |
Correct |
28 ms |
10832 KB |
Output is correct |
52 |
Correct |
35 ms |
10744 KB |
Output is correct |
53 |
Correct |
12 ms |
3932 KB |
Output is correct |
54 |
Correct |
31 ms |
9772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
4 ms |
3316 KB |
Output is correct |
6 |
Correct |
1 ms |
3316 KB |
Output is correct |
7 |
Correct |
1 ms |
3168 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
2 ms |
3416 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3164 KB |
Output is correct |
13 |
Correct |
11 ms |
3676 KB |
Output is correct |
14 |
Correct |
18 ms |
4176 KB |
Output is correct |
15 |
Correct |
15 ms |
3928 KB |
Output is correct |
16 |
Runtime error |
60 ms |
19028 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3324 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
6 ms |
3164 KB |
Output is correct |
5 |
Correct |
13 ms |
4080 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3416 KB |
Output is correct |
9 |
Correct |
34 ms |
6300 KB |
Output is correct |
10 |
Correct |
165 ms |
16724 KB |
Output is correct |
11 |
Correct |
4 ms |
3416 KB |
Output is correct |
12 |
Correct |
17 ms |
4084 KB |
Output is correct |
13 |
Runtime error |
112 ms |
31432 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |