# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994227 |
2024-06-07T09:28:54 Z |
vjudge1 |
Jail (JOI22_jail) |
C++17 |
|
2 ms |
5724 KB |
#include <iostream>
#include <vector>
using namespace std;
int n, m, sz, c;
bool ans;
vector <vector <int>> g(2e5);
vector <int> to(2e5, 0);
vector <bool> del(2e5);
void reset() {
ans = true;
for (int i = 1; i <= n; i++) {
g[i].clear();
del[i] = false;
}
}
int get_c(int x) {
if (del[x]) return 0;
del[x] = true;
int mx = 0, sum = 1;
for (int i : g[x]) {
}
return sum;
}
void cd(int x) {
sz = get_c(x);
get_c(x);
}
bool dfs(int x, int y) {
if (del[x] || to[x]) return false;
if (x == y) return true;
del[x] = true;
bool ret = false;
for (int i : g[x]) if (dfs(i, y)) ret = true;
del[x] = false;
return ret;
}
bool bt() {
bool kesz = true;
for (int i = 1; i <= n; i++) if (to[i] && to[i] != i) kesz = false;
if (kesz) return true;
for (int i = 1; i <= n; i++) {
if (!to[i] || to[i] == i) continue;
int a = to[i];
to[i] = 0;
bool jo = dfs(i, a);
to[i] = a;
if (!jo) continue;
swap(to[i], to[a]);
if (bt()) return true;
swap(to[i], to[a]);
}
return false;
}
void solve() {
cin >> n;
reset();
int a, b;
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
to[a] = b;
}
cout << (bt() ? "YES\n" : "NO\n");
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) solve();
}
Compilation message
jail.cpp: In function 'int get_c(int)':
jail.cpp:23:11: warning: unused variable 'i' [-Wunused-variable]
23 | for (int i : g[x]) {
| ^
jail.cpp:22:6: warning: unused variable 'mx' [-Wunused-variable]
22 | int mx = 0, sum = 1;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |