#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int, int>>> g;
vector<pair<int, int>> ra;
int in;
void dfs(int v, int la){
ra[v].first=in++;
for (auto u: g[v]){
if (u.first!=la){
dfs(u.first, v);
}
}
ra[v].second=in++;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(NULL);
int n, s, q, e;
cin>>n>>s>>q>>e;
e--;
vector<pair<int, int>> ed(n-1);
g.resize(n);
//cout<<'a'<<endl;
for (int i=0; i<n-1; i++){
int a, b, w;
cin>>a>>b>>w;
a--;
b--;
ed[i]={a, b};
g[a].push_back({b, w});
g[b].push_back({a, w});
}
//cout<<'b'<<endl;
ra.resize(n);
in=0;
dfs(e, -1);
vector<int> sh(s);
for (int i=0; i<s; i++){
cin>>sh[s];
}
/*for (auto u: ra){
cout<<u.first<<" "<<u.second<<"\n";
}*/
for (int i=0; i<q; i++){
int e0, v;
cin>>e0>>v;
e0--;
v--;
int a=ed[e0].first, b=ed[e0].second;
if (ra[a].first<ra[b].first){
swap(a, b);
}
//cout<<ra[a].first<<" "<<ra[a].second<<" "<<ra[b].first<<" "<<ra[b].second<<" "<<ra[v].first<<" "<<ra[v].second<<"\n";
if (ra[a].first<=ra[v].first and ra[v].second<=ra[a].second){
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... |