# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884842 |
2023-12-08T14:36:49 Z |
Ahmed57 |
Jail (JOI22_jail) |
C++17 |
|
6 ms |
3420 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();
}
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);
}
}
while(!qe.empty()){
int x = qe.front();qe.pop();
cnt++;
for(auto j:tree[x]){
deg[j]--;
if(deg[j]==0){
qe.push(j);
}
}
}
if(cnt==q)cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:40: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]
40 | for(int i = 0;i<qu.size();i++){
| ~^~~~~~~~~~
jail.cpp:48: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]
48 | for(int j = 0;j<qu.size();j++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
6 ms |
3420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3300 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3300 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3300 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3300 KB |
Output is correct |
2 |
Correct |
1 ms |
3164 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3164 KB |
Output isn't correct |
4 |
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 |
1 ms |
3164 KB |
Output is correct |
5 |
Incorrect |
4 ms |
3420 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3164 KB |
Output is correct |
2 |
Correct |
2 ms |
3164 KB |
Output is correct |
3 |
Correct |
1 ms |
3164 KB |
Output is correct |
4 |
Incorrect |
6 ms |
3420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |