This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |