# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580279 |
2022-06-21T02:44:50 Z |
balbit |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
872128 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define f first
#define s second
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define FOR(i,a,b) for (int i = a; i<b; ++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 2e5+5;
vector<int> tree[maxn];
int dep[maxn];
int fa[18][maxn];
void dfs(int v, int p) {
for (int u : tree[v]) {
if (u == p) continue;
dep[u] = dep[v] + 1;
fa[0][u] = v;
dfs(u,v);
}
}
int st[maxn], en[maxn]; // starting or ending???
int snode[maxn], enode[maxn];
void CLR(int n){
REP(i,n) {
tree[i].clear(); dep[i] = 0;
st[i] = en[i] = -1;
}
}
vector<int> g[maxn];
int indeg[maxn];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
int T; cin>>T;
while (T--) {
int n; cin>>n;
CLR(n);
REP(i,n-1) {
int a,b; cin>>a>>b; --a; --b;
tree[a].pb(b); tree[b].pb(a);
}
dfs(0,-1);
int q; cin>>q;
REP(i,q) {
cin>>snode[i]>>enode[i]; --snode[i]; --enode[i];
st[snode[i]] = i; en[enode[i]] = i;
}
REP(i,q) g[i].clear();
REP(i,q) {
int a = snode[i], b = enode[i];
bool yo = 0;
while (a!=b || yo) {
if (dep[a] < dep[b]) swap(a,b);
// walk a
if (~st[a] && st[a] != i) {
g[i].pb(st[a]);
bug(i, st[a]);
}
if (~en[a] && en[a] != i) {
g[en[a]].pb(i);
bug(en[a], i);
}
if (yo) break;
a = fa[0][a];
if (a == b) yo = 1;
}
}
REP(i,q) {
indeg[i] = 0;
}
REP(i,q) {
for (int u : g[i]) {
++indeg[u];
}
}
queue<int> qq;
REP(i,q) {
if (indeg[i] == 0) {
qq.push(i);
}
}
int done = 0;
while (!qq.empty() ){
int v = qq.front(); qq.pop();
++done;
for (int u : g[v]) {
if (--indeg[u] == 0) {
qq.push(u);
}
}
}
bug(done);
cout<<(done==q?"Yes":"No")<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9728 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Correct |
12 ms |
10004 KB |
Output is correct |
5 |
Correct |
22 ms |
10452 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9796 KB |
Output is correct |
8 |
Correct |
7 ms |
9872 KB |
Output is correct |
9 |
Correct |
88 ms |
13584 KB |
Output is correct |
10 |
Correct |
228 ms |
25632 KB |
Output is correct |
11 |
Correct |
11 ms |
9812 KB |
Output is correct |
12 |
Correct |
38 ms |
10816 KB |
Output is correct |
13 |
Correct |
158 ms |
55180 KB |
Output is correct |
14 |
Correct |
169 ms |
68996 KB |
Output is correct |
15 |
Execution timed out |
5085 ms |
872128 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9744 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
8 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
9792 KB |
Output is correct |
11 |
Correct |
6 ms |
9808 KB |
Output is correct |
12 |
Correct |
6 ms |
9736 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9744 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
8 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
9792 KB |
Output is correct |
11 |
Correct |
6 ms |
9808 KB |
Output is correct |
12 |
Correct |
6 ms |
9736 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9812 KB |
Output is correct |
16 |
Correct |
7 ms |
9912 KB |
Output is correct |
17 |
Correct |
6 ms |
9808 KB |
Output is correct |
18 |
Correct |
6 ms |
9760 KB |
Output is correct |
19 |
Correct |
6 ms |
9672 KB |
Output is correct |
20 |
Correct |
8 ms |
9816 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9752 KB |
Output is correct |
23 |
Correct |
6 ms |
9732 KB |
Output is correct |
24 |
Correct |
6 ms |
9740 KB |
Output is correct |
25 |
Correct |
6 ms |
9804 KB |
Output is correct |
26 |
Correct |
5 ms |
9684 KB |
Output is correct |
27 |
Correct |
6 ms |
9812 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9744 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
8 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
9792 KB |
Output is correct |
11 |
Correct |
6 ms |
9808 KB |
Output is correct |
12 |
Correct |
6 ms |
9736 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9812 KB |
Output is correct |
16 |
Correct |
7 ms |
9912 KB |
Output is correct |
17 |
Correct |
6 ms |
9808 KB |
Output is correct |
18 |
Correct |
6 ms |
9760 KB |
Output is correct |
19 |
Correct |
6 ms |
9672 KB |
Output is correct |
20 |
Correct |
8 ms |
9816 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9752 KB |
Output is correct |
23 |
Correct |
6 ms |
9732 KB |
Output is correct |
24 |
Correct |
6 ms |
9740 KB |
Output is correct |
25 |
Correct |
6 ms |
9804 KB |
Output is correct |
26 |
Correct |
5 ms |
9684 KB |
Output is correct |
27 |
Correct |
6 ms |
9812 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
8 ms |
9876 KB |
Output is correct |
30 |
Correct |
7 ms |
9744 KB |
Output is correct |
31 |
Correct |
9 ms |
9744 KB |
Output is correct |
32 |
Correct |
8 ms |
9684 KB |
Output is correct |
33 |
Correct |
8 ms |
9812 KB |
Output is correct |
34 |
Correct |
7 ms |
9812 KB |
Output is correct |
35 |
Correct |
8 ms |
9812 KB |
Output is correct |
36 |
Correct |
7 ms |
9744 KB |
Output is correct |
37 |
Correct |
6 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9808 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
7 ms |
9744 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
7 ms |
9812 KB |
Output is correct |
8 |
Correct |
6 ms |
9812 KB |
Output is correct |
9 |
Correct |
8 ms |
9812 KB |
Output is correct |
10 |
Correct |
8 ms |
9792 KB |
Output is correct |
11 |
Correct |
6 ms |
9808 KB |
Output is correct |
12 |
Correct |
6 ms |
9736 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
6 ms |
9684 KB |
Output is correct |
15 |
Correct |
6 ms |
9812 KB |
Output is correct |
16 |
Correct |
7 ms |
9912 KB |
Output is correct |
17 |
Correct |
6 ms |
9808 KB |
Output is correct |
18 |
Correct |
6 ms |
9760 KB |
Output is correct |
19 |
Correct |
6 ms |
9672 KB |
Output is correct |
20 |
Correct |
8 ms |
9816 KB |
Output is correct |
21 |
Correct |
7 ms |
9812 KB |
Output is correct |
22 |
Correct |
7 ms |
9752 KB |
Output is correct |
23 |
Correct |
6 ms |
9732 KB |
Output is correct |
24 |
Correct |
6 ms |
9740 KB |
Output is correct |
25 |
Correct |
6 ms |
9804 KB |
Output is correct |
26 |
Correct |
5 ms |
9684 KB |
Output is correct |
27 |
Correct |
6 ms |
9812 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
8 ms |
9876 KB |
Output is correct |
30 |
Correct |
7 ms |
9744 KB |
Output is correct |
31 |
Correct |
9 ms |
9744 KB |
Output is correct |
32 |
Correct |
8 ms |
9684 KB |
Output is correct |
33 |
Correct |
8 ms |
9812 KB |
Output is correct |
34 |
Correct |
7 ms |
9812 KB |
Output is correct |
35 |
Correct |
8 ms |
9812 KB |
Output is correct |
36 |
Correct |
7 ms |
9744 KB |
Output is correct |
37 |
Correct |
6 ms |
9812 KB |
Output is correct |
38 |
Correct |
87 ms |
13444 KB |
Output is correct |
39 |
Correct |
232 ms |
25576 KB |
Output is correct |
40 |
Correct |
70 ms |
12452 KB |
Output is correct |
41 |
Correct |
30 ms |
11020 KB |
Output is correct |
42 |
Correct |
50 ms |
12512 KB |
Output is correct |
43 |
Correct |
25 ms |
11340 KB |
Output is correct |
44 |
Correct |
12 ms |
10196 KB |
Output is correct |
45 |
Correct |
54 ms |
16856 KB |
Output is correct |
46 |
Correct |
47 ms |
16744 KB |
Output is correct |
47 |
Correct |
73 ms |
20592 KB |
Output is correct |
48 |
Correct |
70 ms |
20636 KB |
Output is correct |
49 |
Correct |
49 ms |
16972 KB |
Output is correct |
50 |
Correct |
50 ms |
16984 KB |
Output is correct |
51 |
Correct |
44 ms |
17712 KB |
Output is correct |
52 |
Correct |
41 ms |
17968 KB |
Output is correct |
53 |
Correct |
14 ms |
10396 KB |
Output is correct |
54 |
Correct |
65 ms |
16712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9732 KB |
Output is correct |
2 |
Correct |
6 ms |
9728 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
9728 KB |
Output is correct |
5 |
Correct |
14 ms |
9876 KB |
Output is correct |
6 |
Correct |
8 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9684 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9736 KB |
Output is correct |
10 |
Correct |
6 ms |
9732 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
7 ms |
9820 KB |
Output is correct |
13 |
Correct |
22 ms |
10328 KB |
Output is correct |
14 |
Correct |
27 ms |
10516 KB |
Output is correct |
15 |
Correct |
25 ms |
10444 KB |
Output is correct |
16 |
Correct |
59 ms |
17420 KB |
Output is correct |
17 |
Correct |
134 ms |
23400 KB |
Output is correct |
18 |
Correct |
251 ms |
43488 KB |
Output is correct |
19 |
Correct |
59 ms |
17484 KB |
Output is correct |
20 |
Correct |
61 ms |
17352 KB |
Output is correct |
21 |
Correct |
62 ms |
17748 KB |
Output is correct |
22 |
Correct |
105 ms |
24152 KB |
Output is correct |
23 |
Correct |
85 ms |
24528 KB |
Output is correct |
24 |
Correct |
102 ms |
23384 KB |
Output is correct |
25 |
Correct |
91 ms |
24628 KB |
Output is correct |
26 |
Correct |
89 ms |
24660 KB |
Output is correct |
27 |
Correct |
106 ms |
22564 KB |
Output is correct |
28 |
Correct |
89 ms |
23712 KB |
Output is correct |
29 |
Correct |
95 ms |
23840 KB |
Output is correct |
30 |
Correct |
91 ms |
20308 KB |
Output is correct |
31 |
Correct |
71 ms |
20316 KB |
Output is correct |
32 |
Correct |
85 ms |
20308 KB |
Output is correct |
33 |
Correct |
70 ms |
20240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9728 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Correct |
5 ms |
9732 KB |
Output is correct |
4 |
Correct |
12 ms |
10004 KB |
Output is correct |
5 |
Correct |
22 ms |
10452 KB |
Output is correct |
6 |
Correct |
6 ms |
9812 KB |
Output is correct |
7 |
Correct |
6 ms |
9796 KB |
Output is correct |
8 |
Correct |
7 ms |
9872 KB |
Output is correct |
9 |
Correct |
88 ms |
13584 KB |
Output is correct |
10 |
Correct |
228 ms |
25632 KB |
Output is correct |
11 |
Correct |
11 ms |
9812 KB |
Output is correct |
12 |
Correct |
38 ms |
10816 KB |
Output is correct |
13 |
Correct |
158 ms |
55180 KB |
Output is correct |
14 |
Correct |
169 ms |
68996 KB |
Output is correct |
15 |
Execution timed out |
5085 ms |
872128 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |