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 endl '\n'
using namespace std;
const int maxn = 120010;
int n, m, s[maxn], f[maxn], used[maxn];
vector<int> v[maxn];
void read(){
cin >> n;
for(int i = 1;i <= n;i++)
v[i].clear();
for(int i = 1;i <= n - 1;i++){
int x, y;
cin >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
cin >> m;
for(int i = 1;i <= m;i++){
cin >> s[i] >> f[i];
}
}
void dfs(int ver){
used[ver] = -1;
for(int nb : v[ver]){
if(used[nb])
continue;
dfs(nb);
}
}
void newFill(){
for(int i = 1;i <= n;i++)
used[i] = 0;
for(int i = 1;i <= m;i++)
used[s[i]]++;
}
void solve(){
read();
for(int i = 1;i <= m;i++){
for(int j = 1;j <= m;j++){
if(i == j)
continue;
int ready = 0;
newFill();
dfs(s[i]);
if(used[f[i]] == -1){
newFill();
used[s[i]]--;
used[f[i]]++;
dfs(s[j]);
if(used[f[j]] == -1)
ready = 1;
}
else{
newFill();
dfs(s[j]);
if(used[f[j]] == -1){
newFill();
used[s[j]]--;
used[f[j]]++;
dfs(s[i]);
if(used[f[i]] == -1)
ready = 1;
}
}
if(ready == 0){
cout << "No\n";
return;
}
}
}
cout << "Yes\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
# | 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... |