# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
994337 |
2024-06-07T11:51:16 Z |
Albertstein |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
28756 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 120'001, mbit = 18;
int n, m;
int dth[maxn];
int S[maxn], T[maxn];
vector <vector <int> > G;
vector <int> w;
vector <vector <int> > g;
vector <vector <int> > stp;
void dfs_lca(int u = 1){
for(int i = 1; i < mbit; i++){
stp[u][i] = stp[stp[u][i - 1]][i - 1];
}
for(auto v : G[u]){
if(v != stp[u][0]){
stp[v][0] = u;
dth[v] = dth[u] + 1;
dfs_lca(v);
}
}
}
int LCA(int u, int v){
if(dth[u] < dth[v]) swap(u, v);
for(int i = mbit - 1; i >= 0; i--){
if(dth[u] - dth[v] >= (1 << i)) u = stp[u][i];
}
if(u == v) return u;
for(int i = mbit - 1; i >= 0; i--){
if(stp[u][i] != stp[v][i]){
u = stp[u][i];
v = stp[v][i];
}
}
return stp[u][0];
}
bool mid(int u, int v, int M){
return ((LCA(u, M) == M) || (LCA(v, M) == M)) && (dth[M] >= dth[LCA(u, v)]);
}
bool dfs_loop(int u){
if(w[u] == 1) return 1;
if(w[u] == 2) return 0;
w[u] = 1;
for(auto v : g[u]){
if(dfs_loop(v)) return 1;
}
w[u] = 2;
return 0;
}
bool sol(){
cin >> n;
G.assign(n + 1, vector<int>());
stp.assign(n + 1, vector<int>(mbit));
for(int i = 1; i < n; i++){
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
dth[1] = 0;
dfs_lca();
//===============
cin >> m;
g.assign(m + 1, vector<int>());
for(int i = 0; i < m; i++){
cin >> S[i] >> T[i];
}
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
if(i == j) continue;
if(mid(S[i], T[i], S[j])) g[i].push_back(j);
if(mid(S[i], T[i], T[j])) g[j].push_back(i);
}
}
w.assign(m + 1, 0);
for(int i = 0; i < m; i++){
if(dfs_loop(i)) return 0;
}
return 1;
}
int main(){
int Q;
ios::sync_with_stdio(0);
cin.tie(0);
cin >> Q;
while(Q--){
cout << (sol() ? "Yes\n" : "No\n");
}
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 |
8 ms |
348 KB |
Output is correct |
5 |
Correct |
17 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
31 ms |
592 KB |
Output is correct |
9 |
Correct |
1402 ms |
3664 KB |
Output is correct |
10 |
Correct |
92 ms |
28680 KB |
Output is correct |
11 |
Correct |
13 ms |
348 KB |
Output is correct |
12 |
Correct |
416 ms |
496 KB |
Output is correct |
13 |
Execution timed out |
5032 ms |
28756 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
520 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 |
396 KB |
Output is correct |
13 |
Correct |
1 ms |
344 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 |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
520 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 |
396 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
520 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 |
396 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
31 ms |
596 KB |
Output is correct |
30 |
Correct |
18 ms |
348 KB |
Output is correct |
31 |
Correct |
21 ms |
348 KB |
Output is correct |
32 |
Correct |
12 ms |
532 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
30 ms |
528 KB |
Output is correct |
35 |
Correct |
45 ms |
348 KB |
Output is correct |
36 |
Correct |
25 ms |
516 KB |
Output is correct |
37 |
Correct |
25 ms |
344 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 |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
520 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 |
396 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 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 |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
31 ms |
596 KB |
Output is correct |
30 |
Correct |
18 ms |
348 KB |
Output is correct |
31 |
Correct |
21 ms |
348 KB |
Output is correct |
32 |
Correct |
12 ms |
532 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
30 ms |
528 KB |
Output is correct |
35 |
Correct |
45 ms |
348 KB |
Output is correct |
36 |
Correct |
25 ms |
516 KB |
Output is correct |
37 |
Correct |
25 ms |
344 KB |
Output is correct |
38 |
Correct |
1365 ms |
3664 KB |
Output is correct |
39 |
Correct |
93 ms |
28568 KB |
Output is correct |
40 |
Correct |
1530 ms |
2644 KB |
Output is correct |
41 |
Correct |
1038 ms |
1372 KB |
Output is correct |
42 |
Correct |
967 ms |
2900 KB |
Output is correct |
43 |
Correct |
37 ms |
1372 KB |
Output is correct |
44 |
Correct |
740 ms |
604 KB |
Output is correct |
45 |
Correct |
201 ms |
19792 KB |
Output is correct |
46 |
Correct |
186 ms |
19540 KB |
Output is correct |
47 |
Correct |
280 ms |
23392 KB |
Output is correct |
48 |
Correct |
279 ms |
23376 KB |
Output is correct |
49 |
Correct |
240 ms |
19796 KB |
Output is correct |
50 |
Correct |
230 ms |
20184 KB |
Output is correct |
51 |
Correct |
73 ms |
20820 KB |
Output is correct |
52 |
Correct |
74 ms |
20916 KB |
Output is correct |
53 |
Correct |
599 ms |
1864 KB |
Output is correct |
54 |
Correct |
142 ms |
19536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
15 ms |
492 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
25 ms |
520 KB |
Output is correct |
13 |
Correct |
356 ms |
348 KB |
Output is correct |
14 |
Correct |
170 ms |
348 KB |
Output is correct |
15 |
Correct |
275 ms |
348 KB |
Output is correct |
16 |
Execution timed out |
5071 ms |
20308 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
8 ms |
348 KB |
Output is correct |
5 |
Correct |
17 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
31 ms |
592 KB |
Output is correct |
9 |
Correct |
1402 ms |
3664 KB |
Output is correct |
10 |
Correct |
92 ms |
28680 KB |
Output is correct |
11 |
Correct |
13 ms |
348 KB |
Output is correct |
12 |
Correct |
416 ms |
496 KB |
Output is correct |
13 |
Execution timed out |
5032 ms |
28756 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |