# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
546332 |
2022-04-07T10:01:54 Z |
Jarif_Rahman |
Jail (JOI22_jail) |
C++17 |
|
3870 ms |
1048576 KB |
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int K = 19;
int n, m;
vector<vector<int>> v;
vector<int> s, t;
vector<vector<int>> sth;
vector<int> state;
vector<int> anc[K];
vector<int> d;
bool cycle;
void dfs1(int nd, int ss, int dis){
for(int x: v[nd]) if(x != ss) dfs1(x, nd, dis+1);
if(ss != -1) anc[0][nd] = ss;
d[nd] = dis;
}
int get_anc(int nd, int h){
for(int i = 0; i < K; i++){
if(h%2 == 1) nd = anc[i][nd];
h/=2;
}
return nd;
}
int lca_jump(int a, int b){
if(a == b) return a;
for(int i = K-1; i >= 0; i--) if(anc[i][a] != anc[i][b])
return lca_jump(anc[i][a], anc[i][b]);
return anc[0][a];
}
int lca(int a, int b){
if(d[b] < d[a]) swap(a, b);
b = get_anc(b, d[b]-d[a]);
return lca_jump(a, b);
}
int fix_path(int a, int b){
if(lca(a, b) == a) return get_anc(b, d[b]-d[a]-1);
return anc[0][a];
}
void dfs2(int nd){
if(state[nd] == 1){
cycle = 1;
return;
}
if(state[nd] == 2) return;
state[nd] = 1;
for(int x: sth[nd]) dfs2(x);
state[nd] = 2;
}
void solve(){
cin >> n;
v.assign(n, {});
fill(anc, anc+K, vector<int>(n, 0));
d.assign(n, 0);
sth.assign(2*n, {});
state.assign(2*n, 0);
for(int i = 0; i < n-1; i++){
int a, b; cin >> a >> b; a--, b--;
v[a].pb(b);
v[b].pb(a);
}
dfs1(0, -1, 0);
for(int p = 1; p < K; p++) for(int i = 0; i < n; i++)
anc[p][i] = anc[p-1][anc[p-1][i]];
cin >> m;
s.assign(m, 0);
t.assign(m, 0);
for(int i = 0; i < m; i++) cin >> s[i] >> t[i], s[i]--, t[i]--;
for(int i = 0; i < m; i++){
sth[s[i]].pb(t[i]+n);
}
auto get_path = [&](int a, int b){
vector<int> rt;
if(d[a] > d[b]) swap(a, b);
while(d[a] != d[b]) rt.pb(b), b = anc[0][b];
while(a != b) rt.pb(a), rt.pb(b), a = anc[0][a], b = anc[0][b];
rt.pb(a);
return rt;
};
for(int i = 0; i < m; i++){
for(int x: get_path(fix_path(s[i], t[i]), t[i])) sth[t[i]+n].pb(x);
for(int x: get_path(s[i], fix_path(t[i], s[i]))) sth[x+n].pb(s[i]);
}
cycle = 0;
for(int i = 0; i < 2*n; i++) if(state[i] == 0) dfs2(i);
cout << (cycle?"No\n":"Yes\n");
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T; cin >> T; while(T--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
12 ms |
408 KB |
Output is correct |
5 |
Correct |
35 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
596 KB |
Output is correct |
9 |
Correct |
449 ms |
50588 KB |
Output is correct |
10 |
Correct |
2827 ms |
511124 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
76 ms |
500 KB |
Output is correct |
13 |
Correct |
348 ms |
107352 KB |
Output is correct |
14 |
Correct |
465 ms |
139464 KB |
Output is correct |
15 |
Runtime error |
3870 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
5 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
3 ms |
480 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
5 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
3 ms |
480 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
3 ms |
340 KB |
Output is correct |
35 |
Correct |
5 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
3 ms |
340 KB |
Output is correct |
38 |
Correct |
495 ms |
50692 KB |
Output is correct |
39 |
Correct |
2591 ms |
511032 KB |
Output is correct |
40 |
Correct |
189 ms |
25288 KB |
Output is correct |
41 |
Correct |
43 ms |
2236 KB |
Output is correct |
42 |
Correct |
159 ms |
22484 KB |
Output is correct |
43 |
Correct |
23 ms |
1740 KB |
Output is correct |
44 |
Correct |
14 ms |
720 KB |
Output is correct |
45 |
Correct |
67 ms |
23928 KB |
Output is correct |
46 |
Correct |
64 ms |
23972 KB |
Output is correct |
47 |
Correct |
434 ms |
116424 KB |
Output is correct |
48 |
Correct |
468 ms |
119660 KB |
Output is correct |
49 |
Correct |
85 ms |
28580 KB |
Output is correct |
50 |
Correct |
85 ms |
28724 KB |
Output is correct |
51 |
Correct |
47 ms |
24476 KB |
Output is correct |
52 |
Correct |
57 ms |
24456 KB |
Output is correct |
53 |
Correct |
12 ms |
2004 KB |
Output is correct |
54 |
Correct |
66 ms |
23104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
11 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
31 ms |
388 KB |
Output is correct |
14 |
Correct |
44 ms |
360 KB |
Output is correct |
15 |
Correct |
38 ms |
368 KB |
Output is correct |
16 |
Correct |
92 ms |
26044 KB |
Output is correct |
17 |
Correct |
311 ms |
38804 KB |
Output is correct |
18 |
Correct |
493 ms |
57972 KB |
Output is correct |
19 |
Correct |
132 ms |
28936 KB |
Output is correct |
20 |
Correct |
137 ms |
29096 KB |
Output is correct |
21 |
Correct |
129 ms |
29176 KB |
Output is correct |
22 |
Correct |
260 ms |
39028 KB |
Output is correct |
23 |
Correct |
230 ms |
38756 KB |
Output is correct |
24 |
Correct |
250 ms |
38704 KB |
Output is correct |
25 |
Correct |
223 ms |
39236 KB |
Output is correct |
26 |
Correct |
251 ms |
39028 KB |
Output is correct |
27 |
Correct |
260 ms |
39304 KB |
Output is correct |
28 |
Correct |
265 ms |
39796 KB |
Output is correct |
29 |
Correct |
262 ms |
35844 KB |
Output is correct |
30 |
Correct |
179 ms |
32256 KB |
Output is correct |
31 |
Correct |
197 ms |
33252 KB |
Output is correct |
32 |
Correct |
188 ms |
31216 KB |
Output is correct |
33 |
Correct |
180 ms |
33140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
12 ms |
408 KB |
Output is correct |
5 |
Correct |
35 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
6 ms |
596 KB |
Output is correct |
9 |
Correct |
449 ms |
50588 KB |
Output is correct |
10 |
Correct |
2827 ms |
511124 KB |
Output is correct |
11 |
Correct |
8 ms |
212 KB |
Output is correct |
12 |
Correct |
76 ms |
500 KB |
Output is correct |
13 |
Correct |
348 ms |
107352 KB |
Output is correct |
14 |
Correct |
465 ms |
139464 KB |
Output is correct |
15 |
Runtime error |
3870 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |