# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994301 |
2024-06-07T10:31:09 Z |
zsombor |
Jail (JOI22_jail) |
C++17 |
|
4774 ms |
1048576 KB |
#include <iostream>
#include <vector>
using namespace std;
int n, m, sz;
bool ans;
vector <vector <int>> g(2e5);
vector <int> dep(2e5, 0);
vector <vector <int>> lift(2e5, vector <int>(20, 0));
vector <int> v1(2e5, 0);
vector <int> v2(2e5, 0);
vector <int> kez(2e5, 0);
vector <int> veg(2e5, 0);
vector <vector <int>> g2(2e5);
vector <bool> be(2e5);
vector <bool> ki(2e5);
//vector <bool> del(2e5);
void reset() {
ans = true;
for (int i = 0; i <= n; i++) {
g[i].clear();
dep[i] = 0;
fill(lift[i].begin(), lift[i].end(), 0);
g2[i].clear();
be[i] = ki[i] = false;
kez[i] = veg[i] = -1;
}
}
/*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);
}*/
void dfs(int x) {
for (int i : g[x]) {
if (i == lift[x][0]) continue;
dep[i] = dep[x] + 1;
lift[i][0] = x;
dfs(i);
}
}
int lca(int a, int b) {
if (dep[a] < dep[b]) swap(a, b);
for (int j = 19; j >= 0; j--) {
if (dep[lift[a][j]] >= dep[b]) a = lift[a][j];
}
if (a == b) return a;
for (int j = 19; j >= 0; j--) {
if (lift[a][j] == lift[b][j]) continue;
a = lift[a][j];
b = lift[b][j];
}
return lift[a][0];
}
int par(int a, int k) {
if (k < 0) return 0;
for (int j = 0; j < 20; j++) {
if (k & (1 << j)) a = lift[a][j];
}
return a;
}
bool on_path(int a, int b, int c) {
int l = lca(a, b);
if (dep[c] < dep[l]) return false;
if (par(a, dep[a] - dep[c]) == c) return true;
if (par(b, dep[b] - dep[c]) == c) return true;
return false;
}
void get_path(int i, int a, int c) {
while (true) {
if (kez[a] > -1 && kez[a] != i) g2[kez[a]].push_back(i);
if (veg[a] > -1 && veg[a] != i) g2[i].push_back(veg[a]);
if (a == c) break;
a = lift[a][0];
}
}
void tp(int x) {
if (be[x] && !ki[x]) ans = false;
if (be[x]) return;
be[x] = true;
for (int i : g2[x]) tp(i);
ki[x] = true;
}
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);
}
dfs(1);
for (int j = 1; j < 20; j++) {
for (int i = 1; i <= n; i++) {
lift[i][j] = lift[lift[i][j - 1]][j - 1];
}
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b;
v1[i] = a; v2[i] = b;
kez[a] = i;
veg[b] = i;
}
for (int i = 0; i < m; i++) {
a = v1[i]; b = v2[i];
int c = lca(a, b);
get_path(i, a, c);
get_path(i, b, c);
}
for (int i = 0; i < m; i++) tp(i);
cout << (ans ? "Yes\n" : "No\n");
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) solve();
}
/*
1
4
1 2
1 3
1 4
3
2 3
3 4
4 2
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
37208 KB |
Output is correct |
2 |
Correct |
18 ms |
37208 KB |
Output is correct |
3 |
Correct |
19 ms |
37124 KB |
Output is correct |
4 |
Correct |
27 ms |
37300 KB |
Output is correct |
5 |
Correct |
33 ms |
37208 KB |
Output is correct |
6 |
Correct |
20 ms |
37212 KB |
Output is correct |
7 |
Correct |
18 ms |
37212 KB |
Output is correct |
8 |
Correct |
18 ms |
37212 KB |
Output is correct |
9 |
Correct |
98 ms |
39756 KB |
Output is correct |
10 |
Correct |
303 ms |
50772 KB |
Output is correct |
11 |
Correct |
22 ms |
37464 KB |
Output is correct |
12 |
Correct |
51 ms |
37980 KB |
Output is correct |
13 |
Correct |
142 ms |
79504 KB |
Output is correct |
14 |
Correct |
172 ms |
93388 KB |
Output is correct |
15 |
Runtime error |
4774 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
37208 KB |
Output is correct |
2 |
Correct |
17 ms |
37212 KB |
Output is correct |
3 |
Correct |
18 ms |
37128 KB |
Output is correct |
4 |
Correct |
18 ms |
37212 KB |
Output is correct |
5 |
Correct |
18 ms |
37212 KB |
Output is correct |
6 |
Correct |
17 ms |
37156 KB |
Output is correct |
7 |
Correct |
18 ms |
37208 KB |
Output is correct |
8 |
Correct |
19 ms |
37212 KB |
Output is correct |
9 |
Correct |
18 ms |
37308 KB |
Output is correct |
10 |
Correct |
18 ms |
37212 KB |
Output is correct |
11 |
Correct |
19 ms |
37212 KB |
Output is correct |
12 |
Correct |
21 ms |
37172 KB |
Output is correct |
13 |
Correct |
18 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
37208 KB |
Output is correct |
2 |
Correct |
17 ms |
37212 KB |
Output is correct |
3 |
Correct |
18 ms |
37128 KB |
Output is correct |
4 |
Correct |
18 ms |
37212 KB |
Output is correct |
5 |
Correct |
18 ms |
37212 KB |
Output is correct |
6 |
Correct |
17 ms |
37156 KB |
Output is correct |
7 |
Correct |
18 ms |
37208 KB |
Output is correct |
8 |
Correct |
19 ms |
37212 KB |
Output is correct |
9 |
Correct |
18 ms |
37308 KB |
Output is correct |
10 |
Correct |
18 ms |
37212 KB |
Output is correct |
11 |
Correct |
19 ms |
37212 KB |
Output is correct |
12 |
Correct |
21 ms |
37172 KB |
Output is correct |
13 |
Correct |
18 ms |
37212 KB |
Output is correct |
14 |
Correct |
18 ms |
37128 KB |
Output is correct |
15 |
Correct |
18 ms |
37212 KB |
Output is correct |
16 |
Correct |
18 ms |
37252 KB |
Output is correct |
17 |
Correct |
19 ms |
37212 KB |
Output is correct |
18 |
Correct |
18 ms |
37212 KB |
Output is correct |
19 |
Correct |
17 ms |
37108 KB |
Output is correct |
20 |
Correct |
19 ms |
37216 KB |
Output is correct |
21 |
Correct |
19 ms |
37212 KB |
Output is correct |
22 |
Correct |
18 ms |
37212 KB |
Output is correct |
23 |
Correct |
19 ms |
37212 KB |
Output is correct |
24 |
Correct |
18 ms |
37100 KB |
Output is correct |
25 |
Correct |
19 ms |
37212 KB |
Output is correct |
26 |
Correct |
21 ms |
37128 KB |
Output is correct |
27 |
Correct |
18 ms |
37208 KB |
Output is correct |
28 |
Correct |
18 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
37208 KB |
Output is correct |
2 |
Correct |
17 ms |
37212 KB |
Output is correct |
3 |
Correct |
18 ms |
37128 KB |
Output is correct |
4 |
Correct |
18 ms |
37212 KB |
Output is correct |
5 |
Correct |
18 ms |
37212 KB |
Output is correct |
6 |
Correct |
17 ms |
37156 KB |
Output is correct |
7 |
Correct |
18 ms |
37208 KB |
Output is correct |
8 |
Correct |
19 ms |
37212 KB |
Output is correct |
9 |
Correct |
18 ms |
37308 KB |
Output is correct |
10 |
Correct |
18 ms |
37212 KB |
Output is correct |
11 |
Correct |
19 ms |
37212 KB |
Output is correct |
12 |
Correct |
21 ms |
37172 KB |
Output is correct |
13 |
Correct |
18 ms |
37212 KB |
Output is correct |
14 |
Correct |
18 ms |
37128 KB |
Output is correct |
15 |
Correct |
18 ms |
37212 KB |
Output is correct |
16 |
Correct |
18 ms |
37252 KB |
Output is correct |
17 |
Correct |
19 ms |
37212 KB |
Output is correct |
18 |
Correct |
18 ms |
37212 KB |
Output is correct |
19 |
Correct |
17 ms |
37108 KB |
Output is correct |
20 |
Correct |
19 ms |
37216 KB |
Output is correct |
21 |
Correct |
19 ms |
37212 KB |
Output is correct |
22 |
Correct |
18 ms |
37212 KB |
Output is correct |
23 |
Correct |
19 ms |
37212 KB |
Output is correct |
24 |
Correct |
18 ms |
37100 KB |
Output is correct |
25 |
Correct |
19 ms |
37212 KB |
Output is correct |
26 |
Correct |
21 ms |
37128 KB |
Output is correct |
27 |
Correct |
18 ms |
37208 KB |
Output is correct |
28 |
Correct |
18 ms |
37212 KB |
Output is correct |
29 |
Correct |
21 ms |
37208 KB |
Output is correct |
30 |
Correct |
18 ms |
37212 KB |
Output is correct |
31 |
Correct |
22 ms |
37292 KB |
Output is correct |
32 |
Correct |
19 ms |
37212 KB |
Output is correct |
33 |
Correct |
18 ms |
37312 KB |
Output is correct |
34 |
Correct |
19 ms |
37212 KB |
Output is correct |
35 |
Correct |
25 ms |
37212 KB |
Output is correct |
36 |
Correct |
18 ms |
37208 KB |
Output is correct |
37 |
Correct |
18 ms |
37176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
37208 KB |
Output is correct |
2 |
Correct |
17 ms |
37212 KB |
Output is correct |
3 |
Correct |
18 ms |
37128 KB |
Output is correct |
4 |
Correct |
18 ms |
37212 KB |
Output is correct |
5 |
Correct |
18 ms |
37212 KB |
Output is correct |
6 |
Correct |
17 ms |
37156 KB |
Output is correct |
7 |
Correct |
18 ms |
37208 KB |
Output is correct |
8 |
Correct |
19 ms |
37212 KB |
Output is correct |
9 |
Correct |
18 ms |
37308 KB |
Output is correct |
10 |
Correct |
18 ms |
37212 KB |
Output is correct |
11 |
Correct |
19 ms |
37212 KB |
Output is correct |
12 |
Correct |
21 ms |
37172 KB |
Output is correct |
13 |
Correct |
18 ms |
37212 KB |
Output is correct |
14 |
Correct |
18 ms |
37128 KB |
Output is correct |
15 |
Correct |
18 ms |
37212 KB |
Output is correct |
16 |
Correct |
18 ms |
37252 KB |
Output is correct |
17 |
Correct |
19 ms |
37212 KB |
Output is correct |
18 |
Correct |
18 ms |
37212 KB |
Output is correct |
19 |
Correct |
17 ms |
37108 KB |
Output is correct |
20 |
Correct |
19 ms |
37216 KB |
Output is correct |
21 |
Correct |
19 ms |
37212 KB |
Output is correct |
22 |
Correct |
18 ms |
37212 KB |
Output is correct |
23 |
Correct |
19 ms |
37212 KB |
Output is correct |
24 |
Correct |
18 ms |
37100 KB |
Output is correct |
25 |
Correct |
19 ms |
37212 KB |
Output is correct |
26 |
Correct |
21 ms |
37128 KB |
Output is correct |
27 |
Correct |
18 ms |
37208 KB |
Output is correct |
28 |
Correct |
18 ms |
37212 KB |
Output is correct |
29 |
Correct |
21 ms |
37208 KB |
Output is correct |
30 |
Correct |
18 ms |
37212 KB |
Output is correct |
31 |
Correct |
22 ms |
37292 KB |
Output is correct |
32 |
Correct |
19 ms |
37212 KB |
Output is correct |
33 |
Correct |
18 ms |
37312 KB |
Output is correct |
34 |
Correct |
19 ms |
37212 KB |
Output is correct |
35 |
Correct |
25 ms |
37212 KB |
Output is correct |
36 |
Correct |
18 ms |
37208 KB |
Output is correct |
37 |
Correct |
18 ms |
37176 KB |
Output is correct |
38 |
Correct |
99 ms |
39760 KB |
Output is correct |
39 |
Correct |
303 ms |
50768 KB |
Output is correct |
40 |
Correct |
82 ms |
39504 KB |
Output is correct |
41 |
Correct |
46 ms |
38228 KB |
Output is correct |
42 |
Correct |
60 ms |
39760 KB |
Output is correct |
43 |
Correct |
38 ms |
38484 KB |
Output is correct |
44 |
Correct |
26 ms |
37464 KB |
Output is correct |
45 |
Correct |
59 ms |
42064 KB |
Output is correct |
46 |
Correct |
59 ms |
42064 KB |
Output is correct |
47 |
Correct |
120 ms |
45652 KB |
Output is correct |
48 |
Correct |
121 ms |
45652 KB |
Output is correct |
49 |
Correct |
71 ms |
42068 KB |
Output is correct |
50 |
Correct |
74 ms |
42152 KB |
Output is correct |
51 |
Correct |
49 ms |
43360 KB |
Output is correct |
52 |
Correct |
48 ms |
43320 KB |
Output is correct |
53 |
Correct |
27 ms |
37724 KB |
Output is correct |
54 |
Correct |
74 ms |
41896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
37208 KB |
Output is correct |
2 |
Correct |
18 ms |
37208 KB |
Output is correct |
3 |
Correct |
19 ms |
37212 KB |
Output is correct |
4 |
Correct |
18 ms |
37208 KB |
Output is correct |
5 |
Correct |
22 ms |
37212 KB |
Output is correct |
6 |
Correct |
18 ms |
37224 KB |
Output is correct |
7 |
Correct |
18 ms |
37212 KB |
Output is correct |
8 |
Correct |
18 ms |
37212 KB |
Output is correct |
9 |
Correct |
18 ms |
37248 KB |
Output is correct |
10 |
Correct |
21 ms |
37132 KB |
Output is correct |
11 |
Correct |
18 ms |
37208 KB |
Output is correct |
12 |
Correct |
19 ms |
37212 KB |
Output is correct |
13 |
Correct |
33 ms |
37212 KB |
Output is correct |
14 |
Correct |
40 ms |
37140 KB |
Output is correct |
15 |
Correct |
36 ms |
37212 KB |
Output is correct |
16 |
Correct |
67 ms |
41528 KB |
Output is correct |
17 |
Correct |
142 ms |
47696 KB |
Output is correct |
18 |
Correct |
282 ms |
71480 KB |
Output is correct |
19 |
Correct |
73 ms |
41296 KB |
Output is correct |
20 |
Correct |
72 ms |
41300 KB |
Output is correct |
21 |
Correct |
70 ms |
41244 KB |
Output is correct |
22 |
Correct |
115 ms |
47488 KB |
Output is correct |
23 |
Correct |
103 ms |
47736 KB |
Output is correct |
24 |
Correct |
105 ms |
47220 KB |
Output is correct |
25 |
Correct |
124 ms |
47308 KB |
Output is correct |
26 |
Correct |
97 ms |
47204 KB |
Output is correct |
27 |
Correct |
143 ms |
46656 KB |
Output is correct |
28 |
Correct |
144 ms |
50892 KB |
Output is correct |
29 |
Correct |
140 ms |
47816 KB |
Output is correct |
30 |
Correct |
88 ms |
45396 KB |
Output is correct |
31 |
Correct |
107 ms |
45772 KB |
Output is correct |
32 |
Correct |
98 ms |
44496 KB |
Output is correct |
33 |
Correct |
118 ms |
45980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
37208 KB |
Output is correct |
2 |
Correct |
18 ms |
37208 KB |
Output is correct |
3 |
Correct |
19 ms |
37124 KB |
Output is correct |
4 |
Correct |
27 ms |
37300 KB |
Output is correct |
5 |
Correct |
33 ms |
37208 KB |
Output is correct |
6 |
Correct |
20 ms |
37212 KB |
Output is correct |
7 |
Correct |
18 ms |
37212 KB |
Output is correct |
8 |
Correct |
18 ms |
37212 KB |
Output is correct |
9 |
Correct |
98 ms |
39756 KB |
Output is correct |
10 |
Correct |
303 ms |
50772 KB |
Output is correct |
11 |
Correct |
22 ms |
37464 KB |
Output is correct |
12 |
Correct |
51 ms |
37980 KB |
Output is correct |
13 |
Correct |
142 ms |
79504 KB |
Output is correct |
14 |
Correct |
172 ms |
93388 KB |
Output is correct |
15 |
Runtime error |
4774 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |