Submission #955729

#TimeUsernameProblemLanguageResultExecution timeMemory
955729aymanrsJail (JOI22_jail)C++14
61 / 100
1031 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; bool f; int T; void dfs(int n, vector<int> g[], int p, bool path[]){ path[n] = true; if(n == T){ f = true; return; } for(int c : g[n]){ if(f) break; if(c == p) continue; dfs(c, g, n, path); } if(!f) path[n] = false; } struct node { vector<node*> l; bool v = false, c = false; }; bool ans; void dfs(node* n){ n->v = n->c = true; for(node* c : n->l){ if(!ans) break; if(c->c){ ans = false; break; } if(!c->v) dfs(c); } n->c = false; } void solve(){ int n,m;cin >> n; vector<int> g[n+1]; for(int i = 1;i < n;i++){ int u, v;cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } cin >> m; bool path[m][n+1]; int s[m], t[m]; int o[m];for(int i = 0;i < m;i++) o[i] = i; for(int i = 0;i < m;i++){ memset(path[i], 0, sizeof(path[i])); cin >> s[i] >> t[i];f = false;T = t[i]; dfs(s[i], g, -1, path[i]); } node mg[m]; for(int i = 0;i < m;i++){ for(int j = i+1;j < m;j++){ if(path[i][s[j]]) mg[i].l.push_back(&mg[j]); if(path[i][t[j]]) mg[j].l.push_back(&mg[i]); swap(i,j); if(path[i][s[j]]) mg[i].l.push_back(&mg[j]); if(path[i][t[j]]) mg[j].l.push_back(&mg[i]); swap(i,j); } } ans = true; for(int i = 0;i < m && ans;i++){ if(!mg[i].v) dfs(&mg[i]); } if(ans)cout << "Yes\n"; else cout << "No\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t;cin >> t; while(t--) solve(); }

Compilation message (stderr)

jail.cpp: In function 'void solve()':
jail.cpp:45:9: warning: variable 'o' set but not used [-Wunused-but-set-variable]
   45 |     int o[m];for(int i = 0;i < m;i++) o[i] = i;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...