Submission #553729

#TimeUsernameProblemLanguageResultExecution timeMemory
553729promaJail (JOI22_jail)C++17
0 / 100
5042 ms432 KiB
#include <bits/stdc++.h> using namespace std; const int N = 300; int n, m, p[N]; vector <int> g[N]; vector <pair<int, int>> v; void dfs(int v) { for (auto i: g[v]) { if (i != p[v]) { p[i] = v; dfs(i); } } } void solve() { cin >> n; for (int i = 1; i <= n; i ++) { g[i].clear(); } for (int i = 1; i < n; i ++) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } cin >> m; v.clear(); v.resize(m); for (int i = 0; i < m; i ++) { cin >> v[i].first >> v[i].second; } do { int flag = 1; for (int i = 0; i < m; i ++) { p[v[i].first] = 0; dfs(v[i].first); for (int j = v[i].second; j != v[i].first; j = p[j]) { for (int k = 0; k < i; k ++) { if (j == v[k].second) flag = 0; } for (int k = i + 1; k < m; k ++) { if (j == v[k].first) flag = 0; } } } if (flag) { cout << "Yes\n"; return; } } while(next_permutation(v.begin(), v.end())); cout << "No\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int q; cin >> q; while (q --) { 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...