Submission #660199

#TimeUsernameProblemLanguageResultExecution timeMemory
660199Sohsoh84Jail (JOI22_jail)C++17
0 / 100
36 ms48200 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; const ll LOG = 20; int n, m, t, tin[MAXN], tout[MAXN], S[MAXN], T[MAXN], Par[MAXN][LOG]; vector<int> adj[MAXN]; void dfs(int v, int p) { tin[v] = ++t; Par[v][0] = p; for (int u : adj[v]) if (u != p) dfs(u, v); tout[v] = t; } inline bool par(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; } inline int LCA(int u, int v) { if (par(u, v)) return u; if (par(v, u)) return v; for (int i = LOG - 1; i >= 0; i--) if (Par[u][i] != 0 && !par(Par[u][i], v)) u = Par[u][i]; return Par[u][0]; } inline bool in_path(int v, int a, int b) { int lca = LCA(a, b); if (!par(lca, v)) return false; return par(v, a) || par(v, b); } inline int solve() { t = 0; for (int i = 0; i < n + 10; i++) adj[i].clear(); cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } dfs(1, 0); for (int i = 1; i < LOG; i++) for (int v = 1; v <= n; v++) Par[v][i] = Par[Par[v][i - 1]][i - 1]; cin >> m; for (int i = 1; i <= m; i++) cin >> S[i] >> T[i]; vector<int> vec; for (int i = 1; i <= m; i++) vec.push_back(i); do { bool flag = true; for (int i = 0; i < m; i++) { for (int j = 0; j < i; j++) flag &= (!in_path(T[vec[j]], S[vec[i]], T[vec[i]])); for (int j = i + 1; j < n; j++) flag &= (!in_path(S[vec[j]], S[vec[i]], T[vec[i]])); } if (flag) return cout << "Yes" << endl, 0; } while (next_permutation(all(vec))); cout << "No" << endl; return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.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...