제출 #553985

#제출 시각아이디문제언어결과실행 시간메모리
553985promaJail (JOI22_jail)C++17
0 / 100
5089 ms420 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 ++) { memset(p, 0, sizeof(p)); dfs(v[i].first); for (int j = v[i].second; j != v[i].first and j; 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...