# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884979 |
2023-12-08T18:38:34 Z |
Ahmed57 |
Jail (JOI22_jail) |
C++17 |
|
77 ms |
20564 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;
}
bool ss = 1;
for(int i = 0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
if(a==i+1&&b==i+2){
}else ss = 0;
}
if(ss){
int q;cin>>q;
vector<int> adj[n+1];multiset<int> lol;
while(q--){
int a,b;cin>>a>>b;
lol.insert(b);
adj[a].push_back(b);
}
for(int i = 1;i<=n;i++){
if(adj[i].empty())continue;
sort(adj[i].begin(),adj[i].end());
if((*lol.begin())<adj[i][0]){
cout<<"No\n";goto z;
}
for(auto j:adj[i])lol.erase(j);
}
cout<<"Yes\n";
}else{
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:64: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]
64 | for(int i = 0;i<qu.size();i++){
| ~^~~~~~~~~~
jail.cpp:72: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]
72 | for(int j = 0;j<qu.size();j++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
6 ms |
4696 KB |
Output is correct |
5 |
Correct |
12 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
16 ms |
4956 KB |
Output is correct |
10 |
Correct |
24 ms |
11100 KB |
Output is correct |
11 |
Correct |
4 ms |
4700 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
45 ms |
15236 KB |
Output is correct |
14 |
Correct |
37 ms |
14932 KB |
Output is correct |
15 |
Correct |
41 ms |
15076 KB |
Output is correct |
16 |
Correct |
77 ms |
20564 KB |
Output is correct |
17 |
Correct |
45 ms |
16196 KB |
Output is correct |
18 |
Correct |
66 ms |
20448 KB |
Output is correct |
19 |
Correct |
48 ms |
15872 KB |
Output is correct |
20 |
Correct |
43 ms |
15956 KB |
Output is correct |
21 |
Correct |
42 ms |
15964 KB |
Output is correct |
22 |
Correct |
41 ms |
15956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4856 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4856 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4728 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4856 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4728 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
2 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4700 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
2 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4856 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4700 KB |
Output is correct |
5 |
Correct |
2 ms |
4696 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
2 ms |
4700 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
1 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
1 ms |
4696 KB |
Output is correct |
15 |
Correct |
1 ms |
4700 KB |
Output is correct |
16 |
Correct |
1 ms |
4700 KB |
Output is correct |
17 |
Correct |
1 ms |
4700 KB |
Output is correct |
18 |
Correct |
2 ms |
4700 KB |
Output is correct |
19 |
Correct |
1 ms |
4700 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4700 KB |
Output is correct |
22 |
Correct |
1 ms |
4700 KB |
Output is correct |
23 |
Correct |
1 ms |
4700 KB |
Output is correct |
24 |
Correct |
1 ms |
4700 KB |
Output is correct |
25 |
Correct |
2 ms |
4728 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
1 ms |
4700 KB |
Output is correct |
28 |
Correct |
1 ms |
4700 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4700 KB |
Output is correct |
31 |
Correct |
2 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
2 ms |
4700 KB |
Output is correct |
34 |
Correct |
2 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4700 KB |
Output is correct |
36 |
Correct |
2 ms |
4700 KB |
Output is correct |
37 |
Correct |
2 ms |
4700 KB |
Output is correct |
38 |
Correct |
16 ms |
4952 KB |
Output is correct |
39 |
Correct |
25 ms |
11088 KB |
Output is correct |
40 |
Correct |
22 ms |
4956 KB |
Output is correct |
41 |
Correct |
24 ms |
4960 KB |
Output is correct |
42 |
Correct |
19 ms |
5280 KB |
Output is correct |
43 |
Correct |
18 ms |
4956 KB |
Output is correct |
44 |
Correct |
9 ms |
4864 KB |
Output is correct |
45 |
Correct |
28 ms |
8440 KB |
Output is correct |
46 |
Correct |
30 ms |
8484 KB |
Output is correct |
47 |
Correct |
52 ms |
11408 KB |
Output is correct |
48 |
Correct |
51 ms |
11092 KB |
Output is correct |
49 |
Correct |
26 ms |
8532 KB |
Output is correct |
50 |
Correct |
29 ms |
8620 KB |
Output is correct |
51 |
Correct |
25 ms |
9220 KB |
Output is correct |
52 |
Correct |
25 ms |
9412 KB |
Output is correct |
53 |
Correct |
12 ms |
5016 KB |
Output is correct |
54 |
Correct |
28 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4700 KB |
Output is correct |
5 |
Correct |
4 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4700 KB |
Output is correct |
9 |
Correct |
1 ms |
4700 KB |
Output is correct |
10 |
Correct |
1 ms |
4952 KB |
Output is correct |
11 |
Correct |
1 ms |
4700 KB |
Output is correct |
12 |
Correct |
2 ms |
4700 KB |
Output is correct |
13 |
Correct |
12 ms |
4700 KB |
Output is correct |
14 |
Correct |
18 ms |
4700 KB |
Output is correct |
15 |
Correct |
15 ms |
4696 KB |
Output is correct |
16 |
Runtime error |
51 ms |
17560 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4700 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
6 ms |
4696 KB |
Output is correct |
5 |
Correct |
12 ms |
4700 KB |
Output is correct |
6 |
Correct |
2 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
16 ms |
4956 KB |
Output is correct |
10 |
Correct |
24 ms |
11100 KB |
Output is correct |
11 |
Correct |
4 ms |
4700 KB |
Output is correct |
12 |
Correct |
20 ms |
4700 KB |
Output is correct |
13 |
Correct |
45 ms |
15236 KB |
Output is correct |
14 |
Correct |
37 ms |
14932 KB |
Output is correct |
15 |
Correct |
41 ms |
15076 KB |
Output is correct |
16 |
Correct |
77 ms |
20564 KB |
Output is correct |
17 |
Correct |
45 ms |
16196 KB |
Output is correct |
18 |
Correct |
66 ms |
20448 KB |
Output is correct |
19 |
Correct |
48 ms |
15872 KB |
Output is correct |
20 |
Correct |
43 ms |
15956 KB |
Output is correct |
21 |
Correct |
42 ms |
15964 KB |
Output is correct |
22 |
Correct |
41 ms |
15956 KB |
Output is correct |
23 |
Correct |
1 ms |
4856 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
1 ms |
4700 KB |
Output is correct |
26 |
Correct |
1 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
4696 KB |
Output is correct |
28 |
Correct |
2 ms |
4700 KB |
Output is correct |
29 |
Correct |
1 ms |
4700 KB |
Output is correct |
30 |
Correct |
1 ms |
4696 KB |
Output is correct |
31 |
Correct |
1 ms |
4700 KB |
Output is correct |
32 |
Correct |
2 ms |
4700 KB |
Output is correct |
33 |
Correct |
1 ms |
4700 KB |
Output is correct |
34 |
Correct |
1 ms |
4700 KB |
Output is correct |
35 |
Correct |
2 ms |
4696 KB |
Output is correct |
36 |
Correct |
1 ms |
4696 KB |
Output is correct |
37 |
Correct |
1 ms |
4700 KB |
Output is correct |
38 |
Correct |
1 ms |
4700 KB |
Output is correct |
39 |
Correct |
1 ms |
4700 KB |
Output is correct |
40 |
Correct |
2 ms |
4700 KB |
Output is correct |
41 |
Correct |
1 ms |
4700 KB |
Output is correct |
42 |
Correct |
2 ms |
4696 KB |
Output is correct |
43 |
Correct |
2 ms |
4700 KB |
Output is correct |
44 |
Correct |
1 ms |
4700 KB |
Output is correct |
45 |
Correct |
1 ms |
4700 KB |
Output is correct |
46 |
Correct |
1 ms |
4700 KB |
Output is correct |
47 |
Correct |
2 ms |
4728 KB |
Output is correct |
48 |
Correct |
1 ms |
4700 KB |
Output is correct |
49 |
Correct |
1 ms |
4700 KB |
Output is correct |
50 |
Correct |
1 ms |
4700 KB |
Output is correct |
51 |
Correct |
2 ms |
4700 KB |
Output is correct |
52 |
Correct |
2 ms |
4700 KB |
Output is correct |
53 |
Correct |
2 ms |
4700 KB |
Output is correct |
54 |
Correct |
2 ms |
4700 KB |
Output is correct |
55 |
Correct |
2 ms |
4700 KB |
Output is correct |
56 |
Correct |
2 ms |
4700 KB |
Output is correct |
57 |
Correct |
2 ms |
4700 KB |
Output is correct |
58 |
Correct |
2 ms |
4700 KB |
Output is correct |
59 |
Correct |
2 ms |
4700 KB |
Output is correct |
60 |
Correct |
16 ms |
4952 KB |
Output is correct |
61 |
Correct |
25 ms |
11088 KB |
Output is correct |
62 |
Correct |
22 ms |
4956 KB |
Output is correct |
63 |
Correct |
24 ms |
4960 KB |
Output is correct |
64 |
Correct |
19 ms |
5280 KB |
Output is correct |
65 |
Correct |
18 ms |
4956 KB |
Output is correct |
66 |
Correct |
9 ms |
4864 KB |
Output is correct |
67 |
Correct |
28 ms |
8440 KB |
Output is correct |
68 |
Correct |
30 ms |
8484 KB |
Output is correct |
69 |
Correct |
52 ms |
11408 KB |
Output is correct |
70 |
Correct |
51 ms |
11092 KB |
Output is correct |
71 |
Correct |
26 ms |
8532 KB |
Output is correct |
72 |
Correct |
29 ms |
8620 KB |
Output is correct |
73 |
Correct |
25 ms |
9220 KB |
Output is correct |
74 |
Correct |
25 ms |
9412 KB |
Output is correct |
75 |
Correct |
12 ms |
5016 KB |
Output is correct |
76 |
Correct |
28 ms |
8276 KB |
Output is correct |
77 |
Correct |
1 ms |
4700 KB |
Output is correct |
78 |
Correct |
1 ms |
4700 KB |
Output is correct |
79 |
Correct |
1 ms |
4696 KB |
Output is correct |
80 |
Correct |
2 ms |
4700 KB |
Output is correct |
81 |
Correct |
4 ms |
4700 KB |
Output is correct |
82 |
Correct |
1 ms |
4700 KB |
Output is correct |
83 |
Correct |
1 ms |
4700 KB |
Output is correct |
84 |
Correct |
2 ms |
4700 KB |
Output is correct |
85 |
Correct |
1 ms |
4700 KB |
Output is correct |
86 |
Correct |
1 ms |
4952 KB |
Output is correct |
87 |
Correct |
1 ms |
4700 KB |
Output is correct |
88 |
Correct |
2 ms |
4700 KB |
Output is correct |
89 |
Correct |
12 ms |
4700 KB |
Output is correct |
90 |
Correct |
18 ms |
4700 KB |
Output is correct |
91 |
Correct |
15 ms |
4696 KB |
Output is correct |
92 |
Runtime error |
51 ms |
17560 KB |
Execution killed with signal 11 |
93 |
Halted |
0 ms |
0 KB |
- |