# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884845 |
2023-12-08T14:43:04 Z |
Ahmed57 |
Jail (JOI22_jail) |
C++17 |
|
163 ms |
29460 KB |
#include <bits/stdc++.h>
using namespace std;
int pr[120001],dep[120001],vis[120001],deg[1001];
vector<int> adj[120001],tree[1001];
void dfs(int i,int ppp){
pr[i] = ppp;
dep[i] = dep[ppp]+1;
for(auto j:adj[i]){
if(j==ppp)continue;
dfs(j,i);
}
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
int t;cin>>t;
z:while(t--){
int n;cin>>n;
for(int i = 1;i<=n;i++){
adj[i].clear();
pr[i] = 0 , dep[i] = 0;
vis[i] = 0;
}
for(int i = 1;i<n;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1,0);
int q;cin>>q;
vector<pair<int,int>> qu;
for(int i = 1;i<=q;i++){
int a,b;
cin>>a>>b;
qu.push_back({a,b});
}
for(int i = 1;i<=q;i++){
deg[i] = 0 ;tree[i].clear();
}
for(int i = 0;i<qu.size();i++){
int x = qu[i].first , y = qu[i].second;
while(x!=y){
if(dep[x]<dep[y])swap(x,y);
vis[x] = i+1;
x = pr[x];
}
vis[x] = i+1;
for(int j = 0;j<qu.size();j++){
if(i==j)continue;
if(vis[qu[j].first]==i+1&&vis[qu[j].second]==i+1){
cout<<"No\n";
goto z;
}
if(vis[qu[j].first]==i+1){
tree[i+1].push_back(j+1);
deg[j+1]++;
}else if(vis[qu[j].second]==i+1){
tree[j+1].push_back(i+1);
deg[i+1]++;
}
}
}
int cnt = 0;queue<int> qe;
for(int i = 1;i<=q;i++){
if(deg[i]==0){
qe.push(i);
}
}
bool ss = 1;
while(!qe.empty()){
int x = qe.front();qe.pop();
cnt++;
for(auto j:tree[x]){
deg[j]--;
if(deg[j]<0){
ss = 0;break;
}
if(deg[j]==0){
qe.push(j);
}
}
if(ss==0)break;
}
if(cnt==q&&ss)cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0;i<qu.size();i++){
| ~^~~~~~~~~~
jail.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int j = 0;j<qu.size();j++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
6 ms |
3164 KB |
Output is correct |
5 |
Correct |
14 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
35 ms |
4992 KB |
Output is correct |
10 |
Correct |
161 ms |
15356 KB |
Output is correct |
11 |
Correct |
4 ms |
3164 KB |
Output is correct |
12 |
Correct |
17 ms |
3164 KB |
Output is correct |
13 |
Runtime error |
108 ms |
29460 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3160 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3160 KB |
Output is correct |
11 |
Correct |
2 ms |
3424 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3160 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3160 KB |
Output is correct |
11 |
Correct |
2 ms |
3424 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
1 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3160 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3160 KB |
Output is correct |
11 |
Correct |
2 ms |
3424 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
1 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
29 |
Correct |
3 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
3164 KB |
Output is correct |
33 |
Correct |
1 ms |
3164 KB |
Output is correct |
34 |
Correct |
3 ms |
3164 KB |
Output is correct |
35 |
Correct |
2 ms |
3164 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
1 ms |
3160 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3160 KB |
Output is correct |
11 |
Correct |
2 ms |
3424 KB |
Output is correct |
12 |
Correct |
1 ms |
3164 KB |
Output is correct |
13 |
Correct |
2 ms |
3164 KB |
Output is correct |
14 |
Correct |
1 ms |
3164 KB |
Output is correct |
15 |
Correct |
1 ms |
3164 KB |
Output is correct |
16 |
Correct |
1 ms |
3164 KB |
Output is correct |
17 |
Correct |
2 ms |
3164 KB |
Output is correct |
18 |
Correct |
2 ms |
3164 KB |
Output is correct |
19 |
Correct |
1 ms |
3164 KB |
Output is correct |
20 |
Correct |
1 ms |
3164 KB |
Output is correct |
21 |
Correct |
2 ms |
3164 KB |
Output is correct |
22 |
Correct |
1 ms |
3164 KB |
Output is correct |
23 |
Correct |
1 ms |
3164 KB |
Output is correct |
24 |
Correct |
1 ms |
3164 KB |
Output is correct |
25 |
Correct |
2 ms |
3160 KB |
Output is correct |
26 |
Correct |
1 ms |
3164 KB |
Output is correct |
27 |
Correct |
2 ms |
3164 KB |
Output is correct |
28 |
Correct |
1 ms |
3164 KB |
Output is correct |
29 |
Correct |
3 ms |
3164 KB |
Output is correct |
30 |
Correct |
2 ms |
3164 KB |
Output is correct |
31 |
Correct |
2 ms |
3164 KB |
Output is correct |
32 |
Correct |
2 ms |
3164 KB |
Output is correct |
33 |
Correct |
1 ms |
3164 KB |
Output is correct |
34 |
Correct |
3 ms |
3164 KB |
Output is correct |
35 |
Correct |
2 ms |
3164 KB |
Output is correct |
36 |
Correct |
2 ms |
3164 KB |
Output is correct |
37 |
Correct |
2 ms |
3164 KB |
Output is correct |
38 |
Correct |
34 ms |
4956 KB |
Output is correct |
39 |
Correct |
163 ms |
15188 KB |
Output is correct |
40 |
Correct |
21 ms |
3672 KB |
Output is correct |
41 |
Correct |
31 ms |
3416 KB |
Output is correct |
42 |
Correct |
24 ms |
3932 KB |
Output is correct |
43 |
Correct |
16 ms |
3704 KB |
Output is correct |
44 |
Correct |
10 ms |
3484 KB |
Output is correct |
45 |
Correct |
32 ms |
8484 KB |
Output is correct |
46 |
Correct |
30 ms |
8280 KB |
Output is correct |
47 |
Correct |
49 ms |
11100 KB |
Output is correct |
48 |
Correct |
52 ms |
11088 KB |
Output is correct |
49 |
Correct |
27 ms |
8540 KB |
Output is correct |
50 |
Correct |
31 ms |
8568 KB |
Output is correct |
51 |
Correct |
27 ms |
9304 KB |
Output is correct |
52 |
Correct |
26 ms |
9308 KB |
Output is correct |
53 |
Correct |
12 ms |
3676 KB |
Output is correct |
54 |
Correct |
32 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
2 ms |
3160 KB |
Output is correct |
4 |
Correct |
1 ms |
3164 KB |
Output is correct |
5 |
Correct |
4 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
3164 KB |
Output is correct |
7 |
Correct |
1 ms |
3164 KB |
Output is correct |
8 |
Correct |
1 ms |
3164 KB |
Output is correct |
9 |
Correct |
1 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
1 ms |
3164 KB |
Output is correct |
12 |
Correct |
2 ms |
3164 KB |
Output is correct |
13 |
Correct |
10 ms |
3336 KB |
Output is correct |
14 |
Correct |
18 ms |
3160 KB |
Output is correct |
15 |
Correct |
15 ms |
3164 KB |
Output is correct |
16 |
Runtime error |
56 ms |
17472 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3160 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Correct |
6 ms |
3164 KB |
Output is correct |
5 |
Correct |
14 ms |
3164 KB |
Output is correct |
6 |
Correct |
2 ms |
3164 KB |
Output is correct |
7 |
Correct |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
3164 KB |
Output is correct |
9 |
Correct |
35 ms |
4992 KB |
Output is correct |
10 |
Correct |
161 ms |
15356 KB |
Output is correct |
11 |
Correct |
4 ms |
3164 KB |
Output is correct |
12 |
Correct |
17 ms |
3164 KB |
Output is correct |
13 |
Runtime error |
108 ms |
29460 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |