#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;
}
sort(v.begin(), v.end());
do {
int flag = 1;
for (int i = 0; i < m; i ++) {
p[v[i].first] = 0;
dfs(v[i].first);
for (int j = v[i].second; j != v[i].first; 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
16 ms |
460 KB |
Output is correct |
5 |
Correct |
34 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
372 KB |
Output is correct |
7 |
Correct |
155 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
5054 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
368 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
368 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
157 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
144 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
73 ms |
344 KB |
Output is correct |
21 |
Correct |
95 ms |
352 KB |
Output is correct |
22 |
Correct |
71 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
212 KB |
Output is correct |
24 |
Correct |
8 ms |
212 KB |
Output is correct |
25 |
Correct |
157 ms |
340 KB |
Output is correct |
26 |
Correct |
22 ms |
340 KB |
Output is correct |
27 |
Correct |
41 ms |
340 KB |
Output is correct |
28 |
Correct |
19 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
368 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
157 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
144 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
73 ms |
344 KB |
Output is correct |
21 |
Correct |
95 ms |
352 KB |
Output is correct |
22 |
Correct |
71 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
212 KB |
Output is correct |
24 |
Correct |
8 ms |
212 KB |
Output is correct |
25 |
Correct |
157 ms |
340 KB |
Output is correct |
26 |
Correct |
22 ms |
340 KB |
Output is correct |
27 |
Correct |
41 ms |
340 KB |
Output is correct |
28 |
Correct |
19 ms |
328 KB |
Output is correct |
29 |
Execution timed out |
5096 ms |
340 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
368 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
372 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
157 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
144 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
73 ms |
344 KB |
Output is correct |
21 |
Correct |
95 ms |
352 KB |
Output is correct |
22 |
Correct |
71 ms |
340 KB |
Output is correct |
23 |
Correct |
6 ms |
212 KB |
Output is correct |
24 |
Correct |
8 ms |
212 KB |
Output is correct |
25 |
Correct |
157 ms |
340 KB |
Output is correct |
26 |
Correct |
22 ms |
340 KB |
Output is correct |
27 |
Correct |
41 ms |
340 KB |
Output is correct |
28 |
Correct |
19 ms |
328 KB |
Output is correct |
29 |
Execution timed out |
5096 ms |
340 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Execution timed out |
5095 ms |
428 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
16 ms |
460 KB |
Output is correct |
5 |
Correct |
34 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
372 KB |
Output is correct |
7 |
Correct |
155 ms |
212 KB |
Output is correct |
8 |
Execution timed out |
5054 ms |
340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |