# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
884852 |
2023-12-08T14:48:58 Z |
Ahmed57 |
Jail (JOI22_jail) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
int pr[120001],dep[120001],vis[120001],deg[1001];
vector<int> adj[120001],tree[1001];
int cnt = 0;queue<int> qe;
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]++;
}
}
}
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&&ss)cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:43: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]
43 | for(int i = 0;i<qu.size();i++){
| ~^~~~~~~~~~
jail.cpp:51: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]
51 | for(int j = 0;j<qu.size();j++){
| ~^~~~~~~~~~
jail.cpp:81:16: error: 'ss' was not declared in this scope
81 | if(cnt==q&&ss)cout<<"Yes\n";
| ^~