# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
884840 | 2023-12-08T14:34:03 Z | Ahmed57 | Jail (JOI22_jail) | C++17 | 2 ms | 3416 KB |
#include <bits/stdc++.h> using namespace std; int pr[120001],dep[120001],vis[120001]; vector<int> adj[120001]; 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++){ 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}); } vector<int> tree[q+1]; int deg[q+1] = {0}; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3164 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3160 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3164 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |