Submission #876773

#TimeUsernameProblemLanguageResultExecution timeMemory
876773IvkosqnJail (JOI22_jail)C++14
0 / 100
2 ms3416 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){ used[ver] = -1; for(int nb : v[ver]){ if(used[nb]) continue; dfs(nb); } } void newFill(){ for(int i = 1;i <= n;i++) used[i] = 0; for(int i = 1;i <= m;i++) used[s[i]]++; } void solve(){ read(); for(int i = 1;i <= m;i++){ for(int j = 1;j <= m;j++){ if(i == j) continue; int ready = 0; newFill(); dfs(s[i]); if(used[f[i]] == -1){ newFill(); used[s[i]]--; used[f[i]]++; dfs(s[j]); if(used[f[j]] == -1) ready = 1; } else{ newFill(); dfs(s[j]); if(used[f[j]] == -1){ newFill(); used[s[j]]--; used[f[j]]++; dfs(s[i]); if(used[f[i]] == -1) ready = 1; } } if(ready == 0){ 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...