# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553066 | 2022-04-24T14:50:01 Z | tht2005 | Jail (JOI22_jail) | C++17 | 5000 ms | 773872 KB |
#include <bits/stdc++.h> using namespace std; const int N = 120005; const int LG = 17; int n, m, cnt, s[N], t[N], in[N], S[N], T[N], tin[N], tout[N], p[N][LG]; vector<int> aj[N], ej[N]; queue<int> q; void dfs(int v, int p_) { tin[v] = ++(*tin); memset(p[v], 0, sizeof(p[v])); p[v][0] = p_; for(int i = 0; i + 1 < LG; ++i) { p[v][i + 1] = p[p[v][i]][i]; } for(int u : aj[v]) { if(u == p_) continue; dfs(u, v); } tout[v] = *tin; } bool anc(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; } int lca(int v, int u) { if(anc(v, u)) return v; if(anc(u, v)) return u; for(int i = LG; i--; ) { if(p[v][i] && !anc(p[v][i], u)) { v = p[v][i]; } } return p[v][0]; } int main() { int _; scanf("%d", &_); while(_--) { scanf("%d", &n); for(int i = 1; i < n; ++i) { int u, v; scanf("%d %d", &u, &v); aj[u].push_back(v); aj[v].push_back(u); } *tin = 0; dfs(1, 0); scanf("%d", &m); for(int i = 1; i <= m; ++i) { scanf("%d %d", s + i, t + i); S[s[i]] = i; T[t[i]] = i; } for(int i = 1; i <= m; ++i) { int x = lca(s[i], t[i]); for(int v = s[i]; v != (*p[x]); v = p[v][0]) { if(S[v] && S[v] != i) { ej[S[v]].push_back(i); } if(T[v] && T[v] != i) { ej[i].push_back(T[v]); } } for(int v = t[i]; v != x; v = p[v][0]) { if(S[v] && S[v] != i) { ej[S[v]].push_back(i); } if(T[v] && T[v] != i) { ej[i].push_back(T[v]); } } } for(int i = 1; i <= m; ++i) { for(int j : ej[i]) { ++in[j]; } } for(int i = 1; i <= m; ++i) { if(in[i] == 0) { q.push(i); } } cnt = 0; while(!q.empty()) { int v = q.front(); q.pop(); ++cnt; for(int u : ej[v]) { if((--in[u]) == 0) { q.push(u); } } } for(int i = 1; i <= n; ++i) { aj[i].clear(); ej[i].clear(); S[i] = 0; T[i] = 0; in[i] = 0; } puts((cnt == m) ? "Yes" : "No"); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5972 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 3 ms | 5972 KB | Output is correct |
4 | Correct | 15 ms | 6104 KB | Output is correct |
5 | Correct | 29 ms | 6008 KB | Output is correct |
6 | Correct | 4 ms | 5972 KB | Output is correct |
7 | Correct | 4 ms | 5972 KB | Output is correct |
8 | Correct | 6 ms | 6100 KB | Output is correct |
9 | Correct | 100 ms | 9832 KB | Output is correct |
10 | Correct | 365 ms | 27760 KB | Output is correct |
11 | Correct | 9 ms | 6140 KB | Output is correct |
12 | Correct | 59 ms | 6908 KB | Output is correct |
13 | Correct | 166 ms | 56556 KB | Output is correct |
14 | Correct | 178 ms | 71404 KB | Output is correct |
15 | Execution timed out | 5070 ms | 773872 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5948 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 5 ms | 5960 KB | Output is correct |
4 | Correct | 5 ms | 5952 KB | Output is correct |
5 | Correct | 5 ms | 5972 KB | Output is correct |
6 | Correct | 7 ms | 5956 KB | Output is correct |
7 | Correct | 6 ms | 6012 KB | Output is correct |
8 | Correct | 5 ms | 6040 KB | Output is correct |
9 | Correct | 6 ms | 5972 KB | Output is correct |
10 | Correct | 5 ms | 5972 KB | Output is correct |
11 | Correct | 4 ms | 5972 KB | Output is correct |
12 | Correct | 4 ms | 5960 KB | Output is correct |
13 | Correct | 4 ms | 5972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5948 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 5 ms | 5960 KB | Output is correct |
4 | Correct | 5 ms | 5952 KB | Output is correct |
5 | Correct | 5 ms | 5972 KB | Output is correct |
6 | Correct | 7 ms | 5956 KB | Output is correct |
7 | Correct | 6 ms | 6012 KB | Output is correct |
8 | Correct | 5 ms | 6040 KB | Output is correct |
9 | Correct | 6 ms | 5972 KB | Output is correct |
10 | Correct | 5 ms | 5972 KB | Output is correct |
11 | Correct | 4 ms | 5972 KB | Output is correct |
12 | Correct | 4 ms | 5960 KB | Output is correct |
13 | Correct | 4 ms | 5972 KB | Output is correct |
14 | Correct | 3 ms | 5972 KB | Output is correct |
15 | Correct | 3 ms | 5940 KB | Output is correct |
16 | Correct | 5 ms | 5956 KB | Output is correct |
17 | Correct | 4 ms | 5972 KB | Output is correct |
18 | Correct | 4 ms | 5972 KB | Output is correct |
19 | Correct | 4 ms | 5972 KB | Output is correct |
20 | Correct | 6 ms | 5948 KB | Output is correct |
21 | Correct | 4 ms | 5972 KB | Output is correct |
22 | Correct | 5 ms | 5972 KB | Output is correct |
23 | Correct | 3 ms | 5972 KB | Output is correct |
24 | Correct | 3 ms | 5940 KB | Output is correct |
25 | Correct | 5 ms | 5964 KB | Output is correct |
26 | Correct | 3 ms | 5972 KB | Output is correct |
27 | Correct | 4 ms | 5972 KB | Output is correct |
28 | Correct | 4 ms | 5972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5948 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 5 ms | 5960 KB | Output is correct |
4 | Correct | 5 ms | 5952 KB | Output is correct |
5 | Correct | 5 ms | 5972 KB | Output is correct |
6 | Correct | 7 ms | 5956 KB | Output is correct |
7 | Correct | 6 ms | 6012 KB | Output is correct |
8 | Correct | 5 ms | 6040 KB | Output is correct |
9 | Correct | 6 ms | 5972 KB | Output is correct |
10 | Correct | 5 ms | 5972 KB | Output is correct |
11 | Correct | 4 ms | 5972 KB | Output is correct |
12 | Correct | 4 ms | 5960 KB | Output is correct |
13 | Correct | 4 ms | 5972 KB | Output is correct |
14 | Correct | 3 ms | 5972 KB | Output is correct |
15 | Correct | 3 ms | 5940 KB | Output is correct |
16 | Correct | 5 ms | 5956 KB | Output is correct |
17 | Correct | 4 ms | 5972 KB | Output is correct |
18 | Correct | 4 ms | 5972 KB | Output is correct |
19 | Correct | 4 ms | 5972 KB | Output is correct |
20 | Correct | 6 ms | 5948 KB | Output is correct |
21 | Correct | 4 ms | 5972 KB | Output is correct |
22 | Correct | 5 ms | 5972 KB | Output is correct |
23 | Correct | 3 ms | 5972 KB | Output is correct |
24 | Correct | 3 ms | 5940 KB | Output is correct |
25 | Correct | 5 ms | 5964 KB | Output is correct |
26 | Correct | 3 ms | 5972 KB | Output is correct |
27 | Correct | 4 ms | 5972 KB | Output is correct |
28 | Correct | 4 ms | 5972 KB | Output is correct |
29 | Correct | 7 ms | 6084 KB | Output is correct |
30 | Correct | 5 ms | 6068 KB | Output is correct |
31 | Correct | 6 ms | 6084 KB | Output is correct |
32 | Correct | 5 ms | 5972 KB | Output is correct |
33 | Correct | 5 ms | 5972 KB | Output is correct |
34 | Correct | 5 ms | 6060 KB | Output is correct |
35 | Correct | 6 ms | 6080 KB | Output is correct |
36 | Correct | 5 ms | 5972 KB | Output is correct |
37 | Correct | 5 ms | 5972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5948 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 5 ms | 5960 KB | Output is correct |
4 | Correct | 5 ms | 5952 KB | Output is correct |
5 | Correct | 5 ms | 5972 KB | Output is correct |
6 | Correct | 7 ms | 5956 KB | Output is correct |
7 | Correct | 6 ms | 6012 KB | Output is correct |
8 | Correct | 5 ms | 6040 KB | Output is correct |
9 | Correct | 6 ms | 5972 KB | Output is correct |
10 | Correct | 5 ms | 5972 KB | Output is correct |
11 | Correct | 4 ms | 5972 KB | Output is correct |
12 | Correct | 4 ms | 5960 KB | Output is correct |
13 | Correct | 4 ms | 5972 KB | Output is correct |
14 | Correct | 3 ms | 5972 KB | Output is correct |
15 | Correct | 3 ms | 5940 KB | Output is correct |
16 | Correct | 5 ms | 5956 KB | Output is correct |
17 | Correct | 4 ms | 5972 KB | Output is correct |
18 | Correct | 4 ms | 5972 KB | Output is correct |
19 | Correct | 4 ms | 5972 KB | Output is correct |
20 | Correct | 6 ms | 5948 KB | Output is correct |
21 | Correct | 4 ms | 5972 KB | Output is correct |
22 | Correct | 5 ms | 5972 KB | Output is correct |
23 | Correct | 3 ms | 5972 KB | Output is correct |
24 | Correct | 3 ms | 5940 KB | Output is correct |
25 | Correct | 5 ms | 5964 KB | Output is correct |
26 | Correct | 3 ms | 5972 KB | Output is correct |
27 | Correct | 4 ms | 5972 KB | Output is correct |
28 | Correct | 4 ms | 5972 KB | Output is correct |
29 | Correct | 7 ms | 6084 KB | Output is correct |
30 | Correct | 5 ms | 6068 KB | Output is correct |
31 | Correct | 6 ms | 6084 KB | Output is correct |
32 | Correct | 5 ms | 5972 KB | Output is correct |
33 | Correct | 5 ms | 5972 KB | Output is correct |
34 | Correct | 5 ms | 6060 KB | Output is correct |
35 | Correct | 6 ms | 6080 KB | Output is correct |
36 | Correct | 5 ms | 5972 KB | Output is correct |
37 | Correct | 5 ms | 5972 KB | Output is correct |
38 | Correct | 92 ms | 9528 KB | Output is correct |
39 | Correct | 368 ms | 28140 KB | Output is correct |
40 | Correct | 67 ms | 9112 KB | Output is correct |
41 | Correct | 37 ms | 7604 KB | Output is correct |
42 | Correct | 52 ms | 9140 KB | Output is correct |
43 | Correct | 35 ms | 7884 KB | Output is correct |
44 | Correct | 12 ms | 6356 KB | Output is correct |
45 | Correct | 73 ms | 21368 KB | Output is correct |
46 | Correct | 75 ms | 21452 KB | Output is correct |
47 | Correct | 119 ms | 24144 KB | Output is correct |
48 | Correct | 127 ms | 24140 KB | Output is correct |
49 | Correct | 71 ms | 21592 KB | Output is correct |
50 | Correct | 79 ms | 21340 KB | Output is correct |
51 | Correct | 53 ms | 21324 KB | Output is correct |
52 | Correct | 55 ms | 22296 KB | Output is correct |
53 | Correct | 13 ms | 6988 KB | Output is correct |
54 | Correct | 79 ms | 21300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5972 KB | Output is correct |
2 | Correct | 3 ms | 5940 KB | Output is correct |
3 | Correct | 3 ms | 5972 KB | Output is correct |
4 | Correct | 3 ms | 5924 KB | Output is correct |
5 | Correct | 10 ms | 6100 KB | Output is correct |
6 | Correct | 4 ms | 5972 KB | Output is correct |
7 | Correct | 4 ms | 5972 KB | Output is correct |
8 | Correct | 3 ms | 5940 KB | Output is correct |
9 | Correct | 4 ms | 5972 KB | Output is correct |
10 | Correct | 3 ms | 5972 KB | Output is correct |
11 | Correct | 4 ms | 5972 KB | Output is correct |
12 | Correct | 5 ms | 5972 KB | Output is correct |
13 | Correct | 26 ms | 6480 KB | Output is correct |
14 | Correct | 36 ms | 6792 KB | Output is correct |
15 | Correct | 32 ms | 6536 KB | Output is correct |
16 | Correct | 89 ms | 21532 KB | Output is correct |
17 | Correct | 195 ms | 26384 KB | Output is correct |
18 | Correct | 326 ms | 47160 KB | Output is correct |
19 | Correct | 87 ms | 21524 KB | Output is correct |
20 | Correct | 88 ms | 20528 KB | Output is correct |
21 | Correct | 89 ms | 20752 KB | Output is correct |
22 | Correct | 119 ms | 28096 KB | Output is correct |
23 | Correct | 119 ms | 28544 KB | Output is correct |
24 | Correct | 114 ms | 26572 KB | Output is correct |
25 | Correct | 121 ms | 26672 KB | Output is correct |
26 | Correct | 120 ms | 28444 KB | Output is correct |
27 | Correct | 142 ms | 25884 KB | Output is correct |
28 | Correct | 135 ms | 26420 KB | Output is correct |
29 | Correct | 157 ms | 27700 KB | Output is correct |
30 | Correct | 117 ms | 24648 KB | Output is correct |
31 | Correct | 111 ms | 23948 KB | Output is correct |
32 | Correct | 156 ms | 24700 KB | Output is correct |
33 | Correct | 116 ms | 23852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5972 KB | Output is correct |
2 | Correct | 3 ms | 5972 KB | Output is correct |
3 | Correct | 3 ms | 5972 KB | Output is correct |
4 | Correct | 15 ms | 6104 KB | Output is correct |
5 | Correct | 29 ms | 6008 KB | Output is correct |
6 | Correct | 4 ms | 5972 KB | Output is correct |
7 | Correct | 4 ms | 5972 KB | Output is correct |
8 | Correct | 6 ms | 6100 KB | Output is correct |
9 | Correct | 100 ms | 9832 KB | Output is correct |
10 | Correct | 365 ms | 27760 KB | Output is correct |
11 | Correct | 9 ms | 6140 KB | Output is correct |
12 | Correct | 59 ms | 6908 KB | Output is correct |
13 | Correct | 166 ms | 56556 KB | Output is correct |
14 | Correct | 178 ms | 71404 KB | Output is correct |
15 | Execution timed out | 5070 ms | 773872 KB | Time limit exceeded |
16 | Halted | 0 ms | 0 KB | - |