# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
666188 |
2022-11-27T17:12:49 Z |
Kahou |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
30400 KB |
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mk make_pair
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1.5e5 + 50;
int n, m, par[20][N], h[N], st[N], ft[N], tim;
int s[N], t[N];
int d[N];
vector<int> adj[N], adj2[N];
queue<int> q;
void dfs(int u, int p) {
h[u] = h[p]+1;
par[0][u] = p;
st[u] = ++tim;
for (int v:adj[u]) {
if (v == p) continue;
dfs(v, u);
}
ft[u] = tim;
}
int Par(int u, int x) {
for (int k = 0; k < 20; k++) {
if (x>>k&1) u = par[k][u];
}
return u;
}
int LCA(int u, int v) {
if (h[u] < h[v]) swap(u, v);
u = Par(u, h[u]-h[v]);
for (int k = 19; k >= 0; k--) {
if (par[k][u] != par[k][v]) u = par[k][u], v = par[k][v];
}
if (u == v) return u;
return par[0][u];
}
bool issub(int u, int v) {
return st[u] <= st[v] && st[v] <= ft[u];
}
void solve() {
tim = 0;
for (int u = 1; u <= n; u++) {
adj[u].clear();
}
for (int u = 1; u <= m; u++) {
adj2[u].clear();
d[u] =0;
}
cin >> n;
for (int i = 1; i <= n-1; i++) {
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
for (int k = 1; k < 20; k++) {
for (int u = 1; u <= n; u++) {
par[k][u] = par[k-1][par[k-1][u]];
}
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> s[i] >> t[i];
}
for (int u = 1; u <= m; u++) {
for (int v = 1; v <= m; v++) {
if (u == v) continue;
int r = LCA(s[u], t[u]);
if (issub(r, s[v]) && (issub(s[v], s[u]) || issub(s[v], t[u]))) {
d[u]++;
adj2[v].push_back(u);
}
if (issub(r, t[v]) && (issub(t[v], s[u]) || issub(t[v], t[u]))) {
d[v]++;
adj2[u].push_back(v);
}
}
}
for (int u = 1; u <= m; u++) {
if (!d[u]) q.push(u);
}
while (q.size()) {
int u =q.front();
q.pop();
for (int v:adj2[u]) {
d[v]--;
if (!d[v]) q.push(v);
}
}
bool flg = 1;
for (int u = 1; u <= m; u++) {
flg = flg&&(!d[u]);
}
cout << (flg? "Yes":"No") << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int tc;
cin >> tc;
while(tc--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7384 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
12 ms |
7772 KB |
Output is correct |
5 |
Correct |
21 ms |
8132 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7652 KB |
Output is correct |
8 |
Correct |
22 ms |
7604 KB |
Output is correct |
9 |
Correct |
443 ms |
11640 KB |
Output is correct |
10 |
Correct |
59 ms |
30400 KB |
Output is correct |
11 |
Correct |
14 ms |
7636 KB |
Output is correct |
12 |
Correct |
220 ms |
8552 KB |
Output is correct |
13 |
Execution timed out |
5066 ms |
30340 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7520 KB |
Output is correct |
5 |
Correct |
6 ms |
7568 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
6 ms |
7572 KB |
Output is correct |
8 |
Correct |
8 ms |
7508 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7524 KB |
Output is correct |
11 |
Correct |
5 ms |
7508 KB |
Output is correct |
12 |
Correct |
10 ms |
7508 KB |
Output is correct |
13 |
Correct |
5 ms |
7448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7520 KB |
Output is correct |
5 |
Correct |
6 ms |
7568 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
6 ms |
7572 KB |
Output is correct |
8 |
Correct |
8 ms |
7508 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7524 KB |
Output is correct |
11 |
Correct |
5 ms |
7508 KB |
Output is correct |
12 |
Correct |
10 ms |
7508 KB |
Output is correct |
13 |
Correct |
5 ms |
7448 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
5 ms |
7576 KB |
Output is correct |
17 |
Correct |
5 ms |
7508 KB |
Output is correct |
18 |
Correct |
5 ms |
7564 KB |
Output is correct |
19 |
Correct |
4 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7520 KB |
Output is correct |
21 |
Correct |
5 ms |
7508 KB |
Output is correct |
22 |
Correct |
5 ms |
7516 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7508 KB |
Output is correct |
25 |
Correct |
5 ms |
7560 KB |
Output is correct |
26 |
Correct |
4 ms |
7508 KB |
Output is correct |
27 |
Correct |
5 ms |
7520 KB |
Output is correct |
28 |
Correct |
4 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7520 KB |
Output is correct |
5 |
Correct |
6 ms |
7568 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
6 ms |
7572 KB |
Output is correct |
8 |
Correct |
8 ms |
7508 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7524 KB |
Output is correct |
11 |
Correct |
5 ms |
7508 KB |
Output is correct |
12 |
Correct |
10 ms |
7508 KB |
Output is correct |
13 |
Correct |
5 ms |
7448 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
5 ms |
7576 KB |
Output is correct |
17 |
Correct |
5 ms |
7508 KB |
Output is correct |
18 |
Correct |
5 ms |
7564 KB |
Output is correct |
19 |
Correct |
4 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7520 KB |
Output is correct |
21 |
Correct |
5 ms |
7508 KB |
Output is correct |
22 |
Correct |
5 ms |
7516 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7508 KB |
Output is correct |
25 |
Correct |
5 ms |
7560 KB |
Output is correct |
26 |
Correct |
4 ms |
7508 KB |
Output is correct |
27 |
Correct |
5 ms |
7520 KB |
Output is correct |
28 |
Correct |
4 ms |
7508 KB |
Output is correct |
29 |
Correct |
22 ms |
7636 KB |
Output is correct |
30 |
Correct |
14 ms |
7588 KB |
Output is correct |
31 |
Correct |
14 ms |
7520 KB |
Output is correct |
32 |
Correct |
10 ms |
7520 KB |
Output is correct |
33 |
Correct |
6 ms |
7520 KB |
Output is correct |
34 |
Correct |
21 ms |
7524 KB |
Output is correct |
35 |
Correct |
22 ms |
7628 KB |
Output is correct |
36 |
Correct |
24 ms |
7636 KB |
Output is correct |
37 |
Correct |
15 ms |
7520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7424 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
4 |
Correct |
5 ms |
7520 KB |
Output is correct |
5 |
Correct |
6 ms |
7568 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
6 ms |
7572 KB |
Output is correct |
8 |
Correct |
8 ms |
7508 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7524 KB |
Output is correct |
11 |
Correct |
5 ms |
7508 KB |
Output is correct |
12 |
Correct |
10 ms |
7508 KB |
Output is correct |
13 |
Correct |
5 ms |
7448 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
5 ms |
7576 KB |
Output is correct |
17 |
Correct |
5 ms |
7508 KB |
Output is correct |
18 |
Correct |
5 ms |
7564 KB |
Output is correct |
19 |
Correct |
4 ms |
7512 KB |
Output is correct |
20 |
Correct |
5 ms |
7520 KB |
Output is correct |
21 |
Correct |
5 ms |
7508 KB |
Output is correct |
22 |
Correct |
5 ms |
7516 KB |
Output is correct |
23 |
Correct |
5 ms |
7380 KB |
Output is correct |
24 |
Correct |
4 ms |
7508 KB |
Output is correct |
25 |
Correct |
5 ms |
7560 KB |
Output is correct |
26 |
Correct |
4 ms |
7508 KB |
Output is correct |
27 |
Correct |
5 ms |
7520 KB |
Output is correct |
28 |
Correct |
4 ms |
7508 KB |
Output is correct |
29 |
Correct |
22 ms |
7636 KB |
Output is correct |
30 |
Correct |
14 ms |
7588 KB |
Output is correct |
31 |
Correct |
14 ms |
7520 KB |
Output is correct |
32 |
Correct |
10 ms |
7520 KB |
Output is correct |
33 |
Correct |
6 ms |
7520 KB |
Output is correct |
34 |
Correct |
21 ms |
7524 KB |
Output is correct |
35 |
Correct |
22 ms |
7628 KB |
Output is correct |
36 |
Correct |
24 ms |
7636 KB |
Output is correct |
37 |
Correct |
15 ms |
7520 KB |
Output is correct |
38 |
Correct |
439 ms |
11584 KB |
Output is correct |
39 |
Correct |
60 ms |
30400 KB |
Output is correct |
40 |
Correct |
507 ms |
10688 KB |
Output is correct |
41 |
Correct |
490 ms |
9504 KB |
Output is correct |
42 |
Correct |
490 ms |
10652 KB |
Output is correct |
43 |
Correct |
28 ms |
9428 KB |
Output is correct |
44 |
Correct |
434 ms |
8072 KB |
Output is correct |
45 |
Correct |
81 ms |
23500 KB |
Output is correct |
46 |
Correct |
82 ms |
23508 KB |
Output is correct |
47 |
Correct |
66 ms |
26276 KB |
Output is correct |
48 |
Correct |
76 ms |
26232 KB |
Output is correct |
49 |
Correct |
69 ms |
23624 KB |
Output is correct |
50 |
Correct |
71 ms |
23544 KB |
Output is correct |
51 |
Correct |
49 ms |
24324 KB |
Output is correct |
52 |
Correct |
47 ms |
24376 KB |
Output is correct |
53 |
Correct |
423 ms |
8828 KB |
Output is correct |
54 |
Correct |
89 ms |
23384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7376 KB |
Output is correct |
4 |
Correct |
5 ms |
7380 KB |
Output is correct |
5 |
Correct |
14 ms |
7548 KB |
Output is correct |
6 |
Correct |
6 ms |
7520 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
5 ms |
7512 KB |
Output is correct |
9 |
Correct |
5 ms |
7508 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
29 ms |
7568 KB |
Output is correct |
13 |
Correct |
195 ms |
8084 KB |
Output is correct |
14 |
Correct |
105 ms |
8264 KB |
Output is correct |
15 |
Correct |
160 ms |
8140 KB |
Output is correct |
16 |
Execution timed out |
5041 ms |
24216 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7384 KB |
Output is correct |
2 |
Correct |
4 ms |
7376 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
12 ms |
7772 KB |
Output is correct |
5 |
Correct |
21 ms |
8132 KB |
Output is correct |
6 |
Correct |
5 ms |
7508 KB |
Output is correct |
7 |
Correct |
5 ms |
7652 KB |
Output is correct |
8 |
Correct |
22 ms |
7604 KB |
Output is correct |
9 |
Correct |
443 ms |
11640 KB |
Output is correct |
10 |
Correct |
59 ms |
30400 KB |
Output is correct |
11 |
Correct |
14 ms |
7636 KB |
Output is correct |
12 |
Correct |
220 ms |
8552 KB |
Output is correct |
13 |
Execution timed out |
5066 ms |
30340 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |