# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
993937 |
2024-06-06T21:02:25 Z |
Peti |
Jail (JOI22_jail) |
C++17 |
|
2062 ms |
1048576 KB |
#include <bits/stdc++.h>
using namespace std;
const int logn = 20;
vector<vector<int>> g, idxs, g2;
vector<vector<int>> lca;
vector<int> in, out;
inline bool parent(int a, int b) { return in[a] <= in[b] && out[b] <= out[a]; }
int get_lca(int a, int b){
if(parent(a, b)) return a;
for(int i = logn-1; i >= 0; i--){
if(!parent(lca[a][i], b)){
a = lca[a][i];
}
}
return lca[a][0];
}
int ido = 0;
void dfs(int x, int p){
lca[x][0] = p;
in[x] = ido++;
for(int y : g[x]){
if(y != p){
dfs(y, x);
}
}
out[x] = ido++;
}
void walk_up(int a, int c, int idx){
while(a != c){
idxs[a].push_back(idx);
a = lca[a][0];
}
}
void update(int a, int b, int idx){
int c = get_lca(a, b);
walk_up(a, c, idx);
walk_up(b, c, idx);
idxs[c].push_back(idx);
}
vector<bool> vis, done;
bool dfs2(int x){
vis[x] = true;
bool res = true;
for(int y : g2[x]){
if(!vis[y]){
res = res && dfs2(y);
} else if(!done[y]){
return false;
}
}
done[x] = true;
return res;
}
void solve(){
int n;
cin>>n;
g.assign(n, vector<int>());
idxs.assign(n, vector<int>());
for(int i = 0; i < n-1; i++){
int a, b;
cin>>a>>b;
--a, --b;
g[a].push_back(b);
g[b].push_back(a);
}
lca.assign(n, vector<int>(logn, 0));
in.assign(n, 0);
out.assign(n, 0);
ido = 0;
dfs(0, 0);
for(int j = 1; j < 20; j++){
for(int i = 0; i < n; i++){
lca[i][j] = lca[lca[i][j-1]][j-1];
}
}
int m;
cin>>m;
vector<pair<int, int>> query(m);
g2.assign(m, vector<int>());
for(int i = 0; i < m; i++){
int a, b;
cin>>a>>b;
--a, --b;
query[i] = {a, b};
update(a, b, i);
}
for(int i = 0; i < m; i++){
for(int x : idxs[query[i].first]){
if(i != x) g2[x].push_back(i);
}
for(int x : idxs[query[i].second]){
if(i != x) g2[i].push_back(x);
}
}
vis.assign(m, false);
done.assign(m, false);
bool ok = true;
for(int i = 0; i < m; i++){
if(!vis[i]){
ok = ok && dfs2(i);
}
}
cout << (ok ? "Yes" : "No") <<'\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
832 KB |
Output is correct |
5 |
Correct |
15 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
101 ms |
16992 KB |
Output is correct |
10 |
Correct |
648 ms |
275280 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
1588 KB |
Output is correct |
13 |
Correct |
166 ms |
100948 KB |
Output is correct |
14 |
Correct |
195 ms |
131260 KB |
Output is correct |
15 |
Runtime error |
2062 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
552 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
552 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
552 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
101 ms |
16980 KB |
Output is correct |
39 |
Correct |
653 ms |
275280 KB |
Output is correct |
40 |
Correct |
79 ms |
9768 KB |
Output is correct |
41 |
Correct |
27 ms |
3160 KB |
Output is correct |
42 |
Correct |
41 ms |
7252 KB |
Output is correct |
43 |
Correct |
20 ms |
2908 KB |
Output is correct |
44 |
Correct |
6 ms |
1112 KB |
Output is correct |
45 |
Correct |
62 ms |
26924 KB |
Output is correct |
46 |
Correct |
52 ms |
26964 KB |
Output is correct |
47 |
Correct |
163 ms |
77140 KB |
Output is correct |
48 |
Correct |
179 ms |
78396 KB |
Output is correct |
49 |
Correct |
74 ms |
29028 KB |
Output is correct |
50 |
Correct |
78 ms |
29280 KB |
Output is correct |
51 |
Correct |
42 ms |
27220 KB |
Output is correct |
52 |
Correct |
42 ms |
27216 KB |
Output is correct |
53 |
Correct |
8 ms |
2904 KB |
Output is correct |
54 |
Correct |
54 ms |
26320 KB |
Output is correct |
# |
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 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
4 ms |
576 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
472 KB |
Output is correct |
13 |
Correct |
13 ms |
988 KB |
Output is correct |
14 |
Correct |
20 ms |
1372 KB |
Output is correct |
15 |
Correct |
17 ms |
1016 KB |
Output is correct |
16 |
Correct |
64 ms |
28872 KB |
Output is correct |
17 |
Correct |
134 ms |
41816 KB |
Output is correct |
18 |
Correct |
280 ms |
69304 KB |
Output is correct |
19 |
Correct |
75 ms |
30800 KB |
Output is correct |
20 |
Correct |
75 ms |
31056 KB |
Output is correct |
21 |
Correct |
75 ms |
30932 KB |
Output is correct |
22 |
Correct |
127 ms |
43596 KB |
Output is correct |
23 |
Correct |
104 ms |
43332 KB |
Output is correct |
24 |
Correct |
110 ms |
43336 KB |
Output is correct |
25 |
Correct |
114 ms |
43448 KB |
Output is correct |
26 |
Correct |
113 ms |
43432 KB |
Output is correct |
27 |
Correct |
126 ms |
43976 KB |
Output is correct |
28 |
Correct |
131 ms |
45512 KB |
Output is correct |
29 |
Correct |
105 ms |
42444 KB |
Output is correct |
30 |
Correct |
102 ms |
37328 KB |
Output is correct |
31 |
Correct |
83 ms |
37808 KB |
Output is correct |
32 |
Correct |
86 ms |
37068 KB |
Output is correct |
33 |
Correct |
93 ms |
37840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
7 ms |
832 KB |
Output is correct |
5 |
Correct |
15 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
101 ms |
16992 KB |
Output is correct |
10 |
Correct |
648 ms |
275280 KB |
Output is correct |
11 |
Correct |
4 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
1588 KB |
Output is correct |
13 |
Correct |
166 ms |
100948 KB |
Output is correct |
14 |
Correct |
195 ms |
131260 KB |
Output is correct |
15 |
Runtime error |
2062 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |