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>
using namespace std;
const int N = 300;
int n, m, p[N];
vector <int> g[N];
vector <pair<int, int>> v;
void dfs(int v) {
for (auto i: g[v]) {
if (i != p[v]) {
p[i] = v;
dfs(i);
}
}
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i ++) {
g[i].clear();
}
for (int i = 1; i < n; i ++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> m;
v.clear();
v.resize(m);
for (int i = 0; i < m; i ++) {
cin >> v[i].first >> v[i].second;
}
do {
int flag = 1;
for (int i = 0; i < m; i ++) {
memset(p, 0, sizeof(p));
dfs(v[i].first);
for (int j = v[i].second; j != v[i].first and j; j = p[j]) {
for (int k = 0; k < i; k ++) {
if (j == v[k].second) flag = 0;
}
for (int k = i + 1; k < m; k ++) {
if (j == v[k].first) flag = 0;
}
}
}
if (flag) {
cout << "Yes\n";
return;
}
} while(next_permutation(v.begin(), v.end()));
cout << "No\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
while (q --) {
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... |