# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
971894 |
2024-04-29T12:52:24 Z |
happy_node |
Jail (JOI22_jail) |
C++17 |
|
1695 ms |
1048576 KB |
#include <bits/stdc++.h>
using namespace std;
const int MX=4e5+5;
int Q,N,M;
int S[MX], T[MX];
vector<int> path[MX]; // store the path between Si and Ti
vector<int> adj[MX];
int par[MX], dep[MX];
void dfs(int v, int p) {
par[v]=p;
for(auto u:adj[v]) {
if(u==p) continue;
dep[u]=dep[v]+1;
dfs(u,v);
}
}
vector<int> ADJ[MX];
int deg[MX];
bool f(int i, int x) {
for(auto y:path[i])
if(y==x) return true;
return false;
}
int cntT[MX], cntS[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin>>Q;
while(Q--) {
cin>>N;
for(int i=1;i<=N;i++) adj[i].clear(), cntT[i]=0, cntS[i]=0, dep[i]=0, par[i]=0;
for(int i=0;i<N-1;i++) {
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cin>>M;
for(int i=0;i<2*N+M;i++) path[i].clear(), ADJ[i].clear(), deg[i]=0;
dep[1]=1;
dfs(1,0);
for(int i=0;i<M;i++) {
cin>>S[i]>>T[i];
vector<int> L,R;
int u=S[i],v=T[i];
while(dep[u]>dep[v]) {
L.push_back(u);
u=par[u];
}
while(dep[v]>dep[u]) {
R.push_back(v);
v=par[v];
}
while(u!=v) {
L.push_back(u);
R.push_back(v);
u=par[u];
v=par[v];
}
for(auto x:L) path[i].push_back(x);
path[i].push_back(u);
reverse(R.begin(),R.end());
for(auto x:R) path[i].push_back(x);
}
for(int i=0;i<M;i++) {
cntS[S[i]]+=1;
cntT[T[i]]+=1;
}
for(int i=0;i<M;i++) {
cntS[S[i]]-=1;
cntT[T[i]]-=1;
for(auto x:path[i]) {
if(cntS[x]) {
ADJ[M-1+x].push_back(i);
deg[i]+=1;
}
if(cntT[x]) {
ADJ[i].push_back(M-1+x+N);
deg[M-1+x+N]+=1;
}
}
ADJ[i].push_back(M-1+S[i]);
deg[M-1+S[i]]+=1;
ADJ[M-1+T[i]+N].push_back(i);
deg[i]+=1;
cntS[S[i]]+=1;
cntT[T[i]]+=1;
}
queue<int> q;
for(int i=0;i<2*N+M;i++) {
if(!deg[i]) {
q.push(i);
}
}
int ans=0;
while(!q.empty()) {
auto v=q.front(); q.pop();
ans+=1;
for(auto u:ADJ[v]) {
deg[u]--;
if(!deg[u]) q.push(u);
}
}
cout<<(ans==2*N+M?"Yes":"No")<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37212 KB |
Output is correct |
2 |
Correct |
8 ms |
37400 KB |
Output is correct |
3 |
Correct |
9 ms |
37212 KB |
Output is correct |
4 |
Correct |
15 ms |
37524 KB |
Output is correct |
5 |
Correct |
24 ms |
38416 KB |
Output is correct |
6 |
Correct |
9 ms |
37212 KB |
Output is correct |
7 |
Correct |
9 ms |
37464 KB |
Output is correct |
8 |
Correct |
11 ms |
37720 KB |
Output is correct |
9 |
Correct |
130 ms |
57464 KB |
Output is correct |
10 |
Correct |
535 ms |
288364 KB |
Output is correct |
11 |
Correct |
14 ms |
37468 KB |
Output is correct |
12 |
Correct |
40 ms |
38484 KB |
Output is correct |
13 |
Correct |
205 ms |
120320 KB |
Output is correct |
14 |
Correct |
224 ms |
147884 KB |
Output is correct |
15 |
Runtime error |
1695 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37208 KB |
Output is correct |
2 |
Correct |
8 ms |
37208 KB |
Output is correct |
3 |
Correct |
8 ms |
37336 KB |
Output is correct |
4 |
Correct |
8 ms |
37212 KB |
Output is correct |
5 |
Correct |
9 ms |
37208 KB |
Output is correct |
6 |
Correct |
9 ms |
37448 KB |
Output is correct |
7 |
Correct |
8 ms |
37452 KB |
Output is correct |
8 |
Correct |
9 ms |
37212 KB |
Output is correct |
9 |
Correct |
9 ms |
37340 KB |
Output is correct |
10 |
Correct |
8 ms |
37212 KB |
Output is correct |
11 |
Correct |
9 ms |
37212 KB |
Output is correct |
12 |
Correct |
8 ms |
37212 KB |
Output is correct |
13 |
Correct |
8 ms |
37212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37208 KB |
Output is correct |
2 |
Correct |
8 ms |
37208 KB |
Output is correct |
3 |
Correct |
8 ms |
37336 KB |
Output is correct |
4 |
Correct |
8 ms |
37212 KB |
Output is correct |
5 |
Correct |
9 ms |
37208 KB |
Output is correct |
6 |
Correct |
9 ms |
37448 KB |
Output is correct |
7 |
Correct |
8 ms |
37452 KB |
Output is correct |
8 |
Correct |
9 ms |
37212 KB |
Output is correct |
9 |
Correct |
9 ms |
37340 KB |
Output is correct |
10 |
Correct |
8 ms |
37212 KB |
Output is correct |
11 |
Correct |
9 ms |
37212 KB |
Output is correct |
12 |
Correct |
8 ms |
37212 KB |
Output is correct |
13 |
Correct |
8 ms |
37212 KB |
Output is correct |
14 |
Correct |
8 ms |
37212 KB |
Output is correct |
15 |
Correct |
8 ms |
37212 KB |
Output is correct |
16 |
Correct |
8 ms |
37440 KB |
Output is correct |
17 |
Correct |
8 ms |
37216 KB |
Output is correct |
18 |
Correct |
8 ms |
37464 KB |
Output is correct |
19 |
Correct |
8 ms |
37212 KB |
Output is correct |
20 |
Correct |
9 ms |
37348 KB |
Output is correct |
21 |
Correct |
8 ms |
37216 KB |
Output is correct |
22 |
Correct |
8 ms |
37468 KB |
Output is correct |
23 |
Correct |
9 ms |
37216 KB |
Output is correct |
24 |
Correct |
9 ms |
37216 KB |
Output is correct |
25 |
Correct |
8 ms |
37212 KB |
Output is correct |
26 |
Correct |
8 ms |
37212 KB |
Output is correct |
27 |
Correct |
10 ms |
37212 KB |
Output is correct |
28 |
Correct |
9 ms |
37208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37208 KB |
Output is correct |
2 |
Correct |
8 ms |
37208 KB |
Output is correct |
3 |
Correct |
8 ms |
37336 KB |
Output is correct |
4 |
Correct |
8 ms |
37212 KB |
Output is correct |
5 |
Correct |
9 ms |
37208 KB |
Output is correct |
6 |
Correct |
9 ms |
37448 KB |
Output is correct |
7 |
Correct |
8 ms |
37452 KB |
Output is correct |
8 |
Correct |
9 ms |
37212 KB |
Output is correct |
9 |
Correct |
9 ms |
37340 KB |
Output is correct |
10 |
Correct |
8 ms |
37212 KB |
Output is correct |
11 |
Correct |
9 ms |
37212 KB |
Output is correct |
12 |
Correct |
8 ms |
37212 KB |
Output is correct |
13 |
Correct |
8 ms |
37212 KB |
Output is correct |
14 |
Correct |
8 ms |
37212 KB |
Output is correct |
15 |
Correct |
8 ms |
37212 KB |
Output is correct |
16 |
Correct |
8 ms |
37440 KB |
Output is correct |
17 |
Correct |
8 ms |
37216 KB |
Output is correct |
18 |
Correct |
8 ms |
37464 KB |
Output is correct |
19 |
Correct |
8 ms |
37212 KB |
Output is correct |
20 |
Correct |
9 ms |
37348 KB |
Output is correct |
21 |
Correct |
8 ms |
37216 KB |
Output is correct |
22 |
Correct |
8 ms |
37468 KB |
Output is correct |
23 |
Correct |
9 ms |
37216 KB |
Output is correct |
24 |
Correct |
9 ms |
37216 KB |
Output is correct |
25 |
Correct |
8 ms |
37212 KB |
Output is correct |
26 |
Correct |
8 ms |
37212 KB |
Output is correct |
27 |
Correct |
10 ms |
37212 KB |
Output is correct |
28 |
Correct |
9 ms |
37208 KB |
Output is correct |
29 |
Correct |
10 ms |
37472 KB |
Output is correct |
30 |
Correct |
9 ms |
37476 KB |
Output is correct |
31 |
Correct |
9 ms |
37472 KB |
Output is correct |
32 |
Correct |
9 ms |
37468 KB |
Output is correct |
33 |
Correct |
9 ms |
37464 KB |
Output is correct |
34 |
Correct |
10 ms |
37584 KB |
Output is correct |
35 |
Correct |
11 ms |
37468 KB |
Output is correct |
36 |
Correct |
9 ms |
37468 KB |
Output is correct |
37 |
Correct |
9 ms |
37468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37208 KB |
Output is correct |
2 |
Correct |
8 ms |
37208 KB |
Output is correct |
3 |
Correct |
8 ms |
37336 KB |
Output is correct |
4 |
Correct |
8 ms |
37212 KB |
Output is correct |
5 |
Correct |
9 ms |
37208 KB |
Output is correct |
6 |
Correct |
9 ms |
37448 KB |
Output is correct |
7 |
Correct |
8 ms |
37452 KB |
Output is correct |
8 |
Correct |
9 ms |
37212 KB |
Output is correct |
9 |
Correct |
9 ms |
37340 KB |
Output is correct |
10 |
Correct |
8 ms |
37212 KB |
Output is correct |
11 |
Correct |
9 ms |
37212 KB |
Output is correct |
12 |
Correct |
8 ms |
37212 KB |
Output is correct |
13 |
Correct |
8 ms |
37212 KB |
Output is correct |
14 |
Correct |
8 ms |
37212 KB |
Output is correct |
15 |
Correct |
8 ms |
37212 KB |
Output is correct |
16 |
Correct |
8 ms |
37440 KB |
Output is correct |
17 |
Correct |
8 ms |
37216 KB |
Output is correct |
18 |
Correct |
8 ms |
37464 KB |
Output is correct |
19 |
Correct |
8 ms |
37212 KB |
Output is correct |
20 |
Correct |
9 ms |
37348 KB |
Output is correct |
21 |
Correct |
8 ms |
37216 KB |
Output is correct |
22 |
Correct |
8 ms |
37468 KB |
Output is correct |
23 |
Correct |
9 ms |
37216 KB |
Output is correct |
24 |
Correct |
9 ms |
37216 KB |
Output is correct |
25 |
Correct |
8 ms |
37212 KB |
Output is correct |
26 |
Correct |
8 ms |
37212 KB |
Output is correct |
27 |
Correct |
10 ms |
37212 KB |
Output is correct |
28 |
Correct |
9 ms |
37208 KB |
Output is correct |
29 |
Correct |
10 ms |
37472 KB |
Output is correct |
30 |
Correct |
9 ms |
37476 KB |
Output is correct |
31 |
Correct |
9 ms |
37472 KB |
Output is correct |
32 |
Correct |
9 ms |
37468 KB |
Output is correct |
33 |
Correct |
9 ms |
37464 KB |
Output is correct |
34 |
Correct |
10 ms |
37584 KB |
Output is correct |
35 |
Correct |
11 ms |
37468 KB |
Output is correct |
36 |
Correct |
9 ms |
37468 KB |
Output is correct |
37 |
Correct |
9 ms |
37468 KB |
Output is correct |
38 |
Correct |
140 ms |
57404 KB |
Output is correct |
39 |
Correct |
536 ms |
288464 KB |
Output is correct |
40 |
Correct |
64 ms |
45572 KB |
Output is correct |
41 |
Correct |
38 ms |
38996 KB |
Output is correct |
42 |
Correct |
55 ms |
46880 KB |
Output is correct |
43 |
Correct |
25 ms |
38740 KB |
Output is correct |
44 |
Correct |
15 ms |
37720 KB |
Output is correct |
45 |
Correct |
46 ms |
44112 KB |
Output is correct |
46 |
Correct |
54 ms |
44056 KB |
Output is correct |
47 |
Correct |
118 ms |
89644 KB |
Output is correct |
48 |
Correct |
123 ms |
91696 KB |
Output is correct |
49 |
Correct |
55 ms |
46440 KB |
Output is correct |
50 |
Correct |
48 ms |
46420 KB |
Output is correct |
51 |
Correct |
36 ms |
44804 KB |
Output is correct |
52 |
Correct |
39 ms |
44884 KB |
Output is correct |
53 |
Correct |
15 ms |
37976 KB |
Output is correct |
54 |
Correct |
57 ms |
43980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
37208 KB |
Output is correct |
2 |
Correct |
8 ms |
37212 KB |
Output is correct |
3 |
Correct |
7 ms |
37392 KB |
Output is correct |
4 |
Correct |
7 ms |
37212 KB |
Output is correct |
5 |
Correct |
12 ms |
37208 KB |
Output is correct |
6 |
Correct |
8 ms |
37340 KB |
Output is correct |
7 |
Correct |
8 ms |
37208 KB |
Output is correct |
8 |
Correct |
8 ms |
37212 KB |
Output is correct |
9 |
Correct |
8 ms |
37208 KB |
Output is correct |
10 |
Correct |
10 ms |
37212 KB |
Output is correct |
11 |
Correct |
8 ms |
37212 KB |
Output is correct |
12 |
Correct |
8 ms |
37468 KB |
Output is correct |
13 |
Correct |
23 ms |
37980 KB |
Output is correct |
14 |
Correct |
31 ms |
38068 KB |
Output is correct |
15 |
Correct |
29 ms |
37980 KB |
Output is correct |
16 |
Correct |
54 ms |
45908 KB |
Output is correct |
17 |
Correct |
138 ms |
58816 KB |
Output is correct |
18 |
Correct |
300 ms |
89224 KB |
Output is correct |
19 |
Correct |
60 ms |
47900 KB |
Output is correct |
20 |
Correct |
66 ms |
48076 KB |
Output is correct |
21 |
Correct |
63 ms |
47956 KB |
Output is correct |
22 |
Correct |
129 ms |
60308 KB |
Output is correct |
23 |
Correct |
107 ms |
59980 KB |
Output is correct |
24 |
Correct |
127 ms |
60880 KB |
Output is correct |
25 |
Correct |
117 ms |
61256 KB |
Output is correct |
26 |
Correct |
112 ms |
61212 KB |
Output is correct |
27 |
Correct |
136 ms |
60100 KB |
Output is correct |
28 |
Correct |
113 ms |
60104 KB |
Output is correct |
29 |
Correct |
124 ms |
60108 KB |
Output is correct |
30 |
Correct |
84 ms |
49876 KB |
Output is correct |
31 |
Correct |
94 ms |
49872 KB |
Output is correct |
32 |
Correct |
87 ms |
52196 KB |
Output is correct |
33 |
Correct |
76 ms |
52060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
37212 KB |
Output is correct |
2 |
Correct |
8 ms |
37400 KB |
Output is correct |
3 |
Correct |
9 ms |
37212 KB |
Output is correct |
4 |
Correct |
15 ms |
37524 KB |
Output is correct |
5 |
Correct |
24 ms |
38416 KB |
Output is correct |
6 |
Correct |
9 ms |
37212 KB |
Output is correct |
7 |
Correct |
9 ms |
37464 KB |
Output is correct |
8 |
Correct |
11 ms |
37720 KB |
Output is correct |
9 |
Correct |
130 ms |
57464 KB |
Output is correct |
10 |
Correct |
535 ms |
288364 KB |
Output is correct |
11 |
Correct |
14 ms |
37468 KB |
Output is correct |
12 |
Correct |
40 ms |
38484 KB |
Output is correct |
13 |
Correct |
205 ms |
120320 KB |
Output is correct |
14 |
Correct |
224 ms |
147884 KB |
Output is correct |
15 |
Runtime error |
1695 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |