#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define int long long
using namespace std;
signed main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<vector<int>> g(n);
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
a--;
b--;
if(a!=i||b!=i+1) return 0;
g[a].push_back(b);
g[b].push_back(a);
}
int m;
cin>>m;
vector<pii> s(m),t(m);
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
s[i]={a,i};
t[i]={b,i};
}
sort(s.begin(),s.end());
sort(t.begin(),t.end());
int ans=1;
for(int i=0;i<m;i++){
if(s[i].S!=t[i].S) ans=0;
}
if(ans) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
21 ms |
692 KB |
Output is correct |
5 |
Correct |
45 ms |
944 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
55 ms |
1768 KB |
Output is correct |
10 |
Correct |
69 ms |
8272 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
54 ms |
1520 KB |
Output is correct |
13 |
Correct |
82 ms |
10576 KB |
Output is correct |
14 |
Correct |
81 ms |
10576 KB |
Output is correct |
15 |
Correct |
86 ms |
10536 KB |
Output is correct |
16 |
Correct |
130 ms |
13452 KB |
Output is correct |
17 |
Correct |
86 ms |
10836 KB |
Output is correct |
18 |
Correct |
110 ms |
13396 KB |
Output is correct |
19 |
Correct |
84 ms |
10832 KB |
Output is correct |
20 |
Correct |
85 ms |
10836 KB |
Output is correct |
21 |
Correct |
89 ms |
10836 KB |
Output is correct |
22 |
Correct |
85 ms |
10836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
21 ms |
692 KB |
Output is correct |
5 |
Correct |
45 ms |
944 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
55 ms |
1768 KB |
Output is correct |
10 |
Correct |
69 ms |
8272 KB |
Output is correct |
11 |
Correct |
11 ms |
344 KB |
Output is correct |
12 |
Correct |
54 ms |
1520 KB |
Output is correct |
13 |
Correct |
82 ms |
10576 KB |
Output is correct |
14 |
Correct |
81 ms |
10576 KB |
Output is correct |
15 |
Correct |
86 ms |
10536 KB |
Output is correct |
16 |
Correct |
130 ms |
13452 KB |
Output is correct |
17 |
Correct |
86 ms |
10836 KB |
Output is correct |
18 |
Correct |
110 ms |
13396 KB |
Output is correct |
19 |
Correct |
84 ms |
10832 KB |
Output is correct |
20 |
Correct |
85 ms |
10836 KB |
Output is correct |
21 |
Correct |
89 ms |
10836 KB |
Output is correct |
22 |
Correct |
85 ms |
10836 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |