제출 #653625

#제출 시각아이디문제언어결과실행 시간메모리
653625Eae02Valley (BOI19_valley)C++17
23 / 100
351 ms19724 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; struct edge { ll to; ll w; }; vector<vector<edge>> adj; vector<bool> hasShop; vector<ll> parent; vector<ll> dfsTravLo; vector<ll> dfsTravHi; vector<ll> dfsTrav; void dfs(ll cur) { dfsTravLo[cur] = dfsTrav.size(); dfsTrav.push_back(cur); for (edge e : adj[cur]) { if (e.to != parent[cur]) { parent[e.to] = cur; dfs(e.to); } } dfsTravHi[cur] = dfsTrav.size(); } int main() { ll N, S, Q, E; cin >> N >> S >> Q >> E; E--; adj.resize(N); vector<pair<ll, ll>> edges(N - 1); for (ll i = 0; i < N - 1; i++) { ll a, b, w; cin >> a >> b >> w; a--; b--; edges[i] = { a, b }; adj[a].push_back({ b, w }); adj[b].push_back({ a, w }); } hasShop.resize(N); for (ll i = 0; i < S; i++) { ll node; cin >> node; hasShop[node - 1] = true; } parent.resize(N, -1); dfsTravLo.resize(N); dfsTravHi.resize(N); dfs(E); for (auto& edge : edges) if (parent[edge.second] != edge.first) swap(edge.first, edge.second); for (ll q = 0; q < Q; q++) { ll blockedEdge, queryNode; cin >> blockedEdge >> queryNode; blockedEdge--; queryNode--; ll blockedLower = edges[blockedEdge].second; if (dfsTravLo[queryNode] >= dfsTravLo[blockedLower] && dfsTravHi[queryNode] <= dfsTravHi[blockedLower]) { cout << "0\n"; } else { cout << "escaped\n"; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...