Submission #1135248

#TimeUsernameProblemLanguageResultExecution timeMemory
1135248mmdrzadaValley (BOI19_valley)C++20
0 / 100
9 ms324 KiB
// Alphine walley #include <bits/stdc++.h> using namespace std; #define int long long #define vi vector<int> #define REP(i, k) for(int i = 0 ; i < k ; i ++) #define pb push_back #define pii pair<int, int> #define ll long long const int N = 1e3+10; int n, s, q, e; vector<pii> adj[N]; bool shop[N]; array<int, 3> E[N]; int dis[N], st[N], fn[N]; int timer; int h[N]; void dfs(int v = 0, int p = -1) { st[v] = timer++; h[v] = (p == -1 ? 0 : h[p] + 1); for(auto [neigh, w]: adj[v]) { if (neigh != p) { dfs(neigh, v); } } fn[v] = timer; } bool zird(int v, int u) { return st[u] <= st[v] && fn[v] <= fn[u]; } int32_t main() { cin >> n >> s >> q >> e; e--; REP(i, n-1) { int a, b, w; cin >> a >> b >> w; a--, b--; E[i] = {a, b, w}; adj[a].pb({b, w}), adj[b].pb({a, w}); } REP(i, s) { int c; cin >> c; c--; shop[c] = true; } dfs(); while(q--) { int a, b; cin >> a >> b; a--; b--; auto [u, v, w] = E[a]; if (h[u] > h[v]) swap(u, v); if (zird(b, v) != zird(e, v)) cout << "0\n"; else cout << "escaped\n"; } 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...