# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
887638 |
2023-12-14T22:03:34 Z |
TAhmed33 |
Jail (JOI22_jail) |
C++ |
|
623 ms |
1048576 KB |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector <int> adj[251];
vector <int> g;
bool dfs (int pos, int par, int c) {
if (pos == c) {
g.push_back(pos);
return 1;
}
bool f = 0;
for (auto j : adj[pos]) {
if (j == par) continue;
f |= dfs(j, pos, c);
}
if (f) g.push_back(pos);
return f;
}
int main () {
int t = 1;
cin >> t;
while (t--) {
cin >> n;
for (int i = 1; i <= n; i++) adj[i].clear();
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cin >> m;
int x, y;
cin >> x >> y;
dfs(x, -1, y);
auto f = g;
g.clear();
cin >> x >> y;
dfs(x, -1, y);
auto e = g;
g.clear();
int cnt = 0;
bool flag = 0;
for (auto i : f) flag |= i == e[0];
cnt += flag;
flag = 0;
for (auto i : e) flag |= i == f[0];
cnt += flag;
cout << (cnt <= 1 ? "Yes\n" : "No\n");
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |