This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |