Submission #876767

#TimeUsernameProblemLanguageResultExecution timeMemory
876767IvkosqnJail (JOI22_jail)C++14
0 / 100
2 ms3396 KiB
#include <bits/stdc++.h> #define endl '\n' using namespace std; const int maxn = 120010; int n, m, s[maxn], f[maxn], used[maxn]; vector<int> v[maxn]; void read(){ cin >> n; for(int i = 1;i <= n;i++) v[i].clear(); for(int i = 1;i <= n - 1;i++){ int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } cin >> m; for(int i = 1;i <= m;i++){ cin >> s[i] >> f[i]; } } void dfs(int ver){ if(used[ver] > 1) return; used[ver] = -1; for(int nb : v[ver]){ if(used[nb]) continue; dfs(nb); } } void solve(){ read(); for(int i = 1;i <= m;i++){ for(int j = 1;j <= m;j++){ if(i == j) continue; for(int k = 1;k <= n;k++) used[k] = 0; for(int k = 1;k <= m;k++) used[s[k]]++; dfs(s[j]); int cnt = 0; if(used[f[j]] != -1) cnt++; for(int k = 1;k <= n;k++) used[k] = 0; for(int k = 1;k <= m;k++) used[s[k]]++; dfs(s[i]); if(used[f[i]] != -1) cnt++; else{ for(int k = 1;k <= n;k++) used[k] = 0; for(int k = 1;k <= m;k++) used[s[k]]++; used[s[i]]--; used[f[i]]++; dfs(s[j]); if(used[f[j]] != -1) cnt++; } if(cnt == 2){ cout << "No\n"; return; } } } cout << "Yes\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--){ solve(); } return 0; }
#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...