# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884985 |
2023-12-08T18:48:57 Z |
MinaRagy06 |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
25556 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 120'005;
vector<int> adj[N];
int st[N], en[N], h[N], anc[N][17], t;
void dfs(int i, int par, int d = 0) {
anc[i][0] = par;
for (int j = 1; j < 17; j++) {
anc[i][j] = anc[anc[i][j - 1]][j - 1];
}
h[i] = d;
st[i] = t++;
for (auto nxt : adj[i]) {
if (nxt == par) continue;
dfs(nxt, i, d + 1);
}
en[i] = t - 1;
}
int getlca(int u, int v) {
if (st[u] <= st[v] && en[v] <= en[u]) {
return u;
}
for (int j = 16; j >= 0; j--) {
int nxtu = anc[u][j];
if (!(st[nxtu] <= st[v] && en[v] <= en[nxtu])) {
u = nxtu;
}
}
return anc[u][0];
}
struct path {
int s, e, lca;
} a[N];
int m;
bool vis[N], instack[N];
bool dfs2(int i) {
vis[i] = 1;
instack[i] = 1;
bool ok = 1;
// cout << i + 1 << '\n';
for (int j = 0; j < m; j++) {
if (j == i) continue;
bool gud = st[a[i].lca] <= st[a[j].s] && st[a[j].s] <= st[a[i].s] && st[a[i].s] <= en[a[j].s];
gud |= st[a[i].lca] <= st[a[j].s] && st[a[j].s] <= st[a[i].e] && st[a[i].e] <= en[a[j].s];
gud |= st[a[i].e] <= st[a[j].s] && st[a[j].s] <= en[a[i].e] && st[a[j].lca] <= st[a[i].e];
gud |= st[a[i].e] <= st[a[j].e] && st[a[j].e] <= en[a[i].e] && st[a[j].lca] <= st[a[i].e];
if (gud) {
if (instack[j]) {
ok = 0;
break;
}
if (vis[j]) continue;
if (!dfs2(j)) {
ok = 0;
break;
}
}
}
instack[i] = 0;
return ok;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
adj[i].clear();
vis[i] = 0;
instack[i] = 0;
}
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
t = 0;
dfs(0, 0);
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a[i].s >> a[i].e;
a[i].s--, a[i].e--;
a[i].lca = getlca(a[i].s, a[i].e);
// cout << a[i].s + 1 << ' ' << a[i].e + 1 << ' ' << a[i].lca + 1 << '\n';
}
auto check = [&] (int i, int x) {
if (st[a[i].lca] <= st[x] && en[x] <= en[a[i].lca] &&
((st[x] <= st[a[i].s] && en[a[i].s] <= en[x]) ||
(st[x] <= st[a[i].e] && en[a[i].e] <= en[x]))) {
return 1;
}
return 0;
};
bool ok = 1;
for (int i = 0; i < m; i++) {
if (vis[i]) continue;
if (!dfs2(i)) {
ok = 0;
}
}
cout << (ok? "Yes\n" : "No\n");
}
return 0;
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:91:8: warning: variable 'check' set but not used [-Wunused-but-set-variable]
91 | auto check = [&] (int i, int x) {
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7772 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
10 ms |
7772 KB |
Output is correct |
5 |
Correct |
18 ms |
7768 KB |
Output is correct |
6 |
Correct |
2 ms |
7772 KB |
Output is correct |
7 |
Correct |
2 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7768 KB |
Output is correct |
9 |
Correct |
38 ms |
8540 KB |
Output is correct |
10 |
Correct |
37 ms |
25556 KB |
Output is correct |
11 |
Correct |
6 ms |
7768 KB |
Output is correct |
12 |
Correct |
33 ms |
7992 KB |
Output is correct |
13 |
Execution timed out |
5070 ms |
25356 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
7772 KB |
Output is correct |
7 |
Correct |
3 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7772 KB |
Output is correct |
9 |
Correct |
3 ms |
7772 KB |
Output is correct |
10 |
Correct |
2 ms |
7772 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
2 ms |
7772 KB |
Output is correct |
13 |
Correct |
2 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
7772 KB |
Output is correct |
7 |
Correct |
3 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7772 KB |
Output is correct |
9 |
Correct |
3 ms |
7772 KB |
Output is correct |
10 |
Correct |
2 ms |
7772 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
2 ms |
7772 KB |
Output is correct |
13 |
Correct |
2 ms |
7772 KB |
Output is correct |
14 |
Correct |
2 ms |
7772 KB |
Output is correct |
15 |
Correct |
2 ms |
7972 KB |
Output is correct |
16 |
Correct |
2 ms |
7772 KB |
Output is correct |
17 |
Correct |
3 ms |
7772 KB |
Output is correct |
18 |
Correct |
2 ms |
7772 KB |
Output is correct |
19 |
Correct |
2 ms |
7772 KB |
Output is correct |
20 |
Correct |
2 ms |
7772 KB |
Output is correct |
21 |
Correct |
2 ms |
7988 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
2 ms |
7772 KB |
Output is correct |
24 |
Correct |
2 ms |
7772 KB |
Output is correct |
25 |
Correct |
4 ms |
7772 KB |
Output is correct |
26 |
Correct |
2 ms |
7772 KB |
Output is correct |
27 |
Correct |
2 ms |
7772 KB |
Output is correct |
28 |
Correct |
2 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
7772 KB |
Output is correct |
7 |
Correct |
3 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7772 KB |
Output is correct |
9 |
Correct |
3 ms |
7772 KB |
Output is correct |
10 |
Correct |
2 ms |
7772 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
2 ms |
7772 KB |
Output is correct |
13 |
Correct |
2 ms |
7772 KB |
Output is correct |
14 |
Correct |
2 ms |
7772 KB |
Output is correct |
15 |
Correct |
2 ms |
7972 KB |
Output is correct |
16 |
Correct |
2 ms |
7772 KB |
Output is correct |
17 |
Correct |
3 ms |
7772 KB |
Output is correct |
18 |
Correct |
2 ms |
7772 KB |
Output is correct |
19 |
Correct |
2 ms |
7772 KB |
Output is correct |
20 |
Correct |
2 ms |
7772 KB |
Output is correct |
21 |
Correct |
2 ms |
7988 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
2 ms |
7772 KB |
Output is correct |
24 |
Correct |
2 ms |
7772 KB |
Output is correct |
25 |
Correct |
4 ms |
7772 KB |
Output is correct |
26 |
Correct |
2 ms |
7772 KB |
Output is correct |
27 |
Correct |
2 ms |
7772 KB |
Output is correct |
28 |
Correct |
2 ms |
7772 KB |
Output is correct |
29 |
Correct |
3 ms |
7772 KB |
Output is correct |
30 |
Correct |
3 ms |
7772 KB |
Output is correct |
31 |
Correct |
4 ms |
7772 KB |
Output is correct |
32 |
Correct |
3 ms |
7772 KB |
Output is correct |
33 |
Correct |
2 ms |
7772 KB |
Output is correct |
34 |
Correct |
3 ms |
7768 KB |
Output is correct |
35 |
Correct |
5 ms |
7772 KB |
Output is correct |
36 |
Correct |
4 ms |
7772 KB |
Output is correct |
37 |
Correct |
3 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7768 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
2 ms |
7772 KB |
Output is correct |
6 |
Correct |
3 ms |
7772 KB |
Output is correct |
7 |
Correct |
3 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7772 KB |
Output is correct |
9 |
Correct |
3 ms |
7772 KB |
Output is correct |
10 |
Correct |
2 ms |
7772 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
2 ms |
7772 KB |
Output is correct |
13 |
Correct |
2 ms |
7772 KB |
Output is correct |
14 |
Correct |
2 ms |
7772 KB |
Output is correct |
15 |
Correct |
2 ms |
7972 KB |
Output is correct |
16 |
Correct |
2 ms |
7772 KB |
Output is correct |
17 |
Correct |
3 ms |
7772 KB |
Output is correct |
18 |
Correct |
2 ms |
7772 KB |
Output is correct |
19 |
Correct |
2 ms |
7772 KB |
Output is correct |
20 |
Correct |
2 ms |
7772 KB |
Output is correct |
21 |
Correct |
2 ms |
7988 KB |
Output is correct |
22 |
Correct |
3 ms |
7768 KB |
Output is correct |
23 |
Correct |
2 ms |
7772 KB |
Output is correct |
24 |
Correct |
2 ms |
7772 KB |
Output is correct |
25 |
Correct |
4 ms |
7772 KB |
Output is correct |
26 |
Correct |
2 ms |
7772 KB |
Output is correct |
27 |
Correct |
2 ms |
7772 KB |
Output is correct |
28 |
Correct |
2 ms |
7772 KB |
Output is correct |
29 |
Correct |
3 ms |
7772 KB |
Output is correct |
30 |
Correct |
3 ms |
7772 KB |
Output is correct |
31 |
Correct |
4 ms |
7772 KB |
Output is correct |
32 |
Correct |
3 ms |
7772 KB |
Output is correct |
33 |
Correct |
2 ms |
7772 KB |
Output is correct |
34 |
Correct |
3 ms |
7768 KB |
Output is correct |
35 |
Correct |
5 ms |
7772 KB |
Output is correct |
36 |
Correct |
4 ms |
7772 KB |
Output is correct |
37 |
Correct |
3 ms |
7772 KB |
Output is correct |
38 |
Correct |
56 ms |
8540 KB |
Output is correct |
39 |
Correct |
34 ms |
25424 KB |
Output is correct |
40 |
Correct |
65 ms |
8284 KB |
Output is correct |
41 |
Correct |
72 ms |
8024 KB |
Output is correct |
42 |
Correct |
64 ms |
8376 KB |
Output is correct |
43 |
Correct |
26 ms |
8336 KB |
Output is correct |
44 |
Correct |
29 ms |
8028 KB |
Output is correct |
45 |
Correct |
44 ms |
18092 KB |
Output is correct |
46 |
Correct |
49 ms |
18000 KB |
Output is correct |
47 |
Correct |
65 ms |
21700 KB |
Output is correct |
48 |
Correct |
44 ms |
21804 KB |
Output is correct |
49 |
Correct |
50 ms |
18168 KB |
Output is correct |
50 |
Correct |
45 ms |
18000 KB |
Output is correct |
51 |
Correct |
40 ms |
19272 KB |
Output is correct |
52 |
Correct |
38 ms |
19292 KB |
Output is correct |
53 |
Correct |
37 ms |
8072 KB |
Output is correct |
54 |
Correct |
71 ms |
18044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
6 ms |
7984 KB |
Output is correct |
6 |
Correct |
2 ms |
7772 KB |
Output is correct |
7 |
Correct |
2 ms |
7996 KB |
Output is correct |
8 |
Correct |
2 ms |
7772 KB |
Output is correct |
9 |
Correct |
2 ms |
7772 KB |
Output is correct |
10 |
Correct |
2 ms |
7768 KB |
Output is correct |
11 |
Correct |
2 ms |
7772 KB |
Output is correct |
12 |
Correct |
4 ms |
8004 KB |
Output is correct |
13 |
Correct |
29 ms |
7968 KB |
Output is correct |
14 |
Correct |
33 ms |
7772 KB |
Output is correct |
15 |
Correct |
33 ms |
7972 KB |
Output is correct |
16 |
Correct |
1269 ms |
18248 KB |
Output is correct |
17 |
Execution timed out |
5055 ms |
18284 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
7772 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7772 KB |
Output is correct |
4 |
Correct |
10 ms |
7772 KB |
Output is correct |
5 |
Correct |
18 ms |
7768 KB |
Output is correct |
6 |
Correct |
2 ms |
7772 KB |
Output is correct |
7 |
Correct |
2 ms |
7772 KB |
Output is correct |
8 |
Correct |
3 ms |
7768 KB |
Output is correct |
9 |
Correct |
38 ms |
8540 KB |
Output is correct |
10 |
Correct |
37 ms |
25556 KB |
Output is correct |
11 |
Correct |
6 ms |
7768 KB |
Output is correct |
12 |
Correct |
33 ms |
7992 KB |
Output is correct |
13 |
Execution timed out |
5070 ms |
25356 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |