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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e5+5;
vector <int> g[N];
set <int> sbtr[N];
int d[N];
void dfs(int v,int p){
for(auto to : g[v]){
if(to!=p){
d[to]=d[v]+1;
dfs(to,v);
}
}
sbtr[v].insert(v);
if(sbtr[p].size()<sbtr[v].size()){
set <int> st=sbtr[v];
swap(sbtr[p],sbtr[v]);
for(auto x : sbtr[v])sbtr[p].insert(x);
sbtr[v]=st;
}
else{
for(auto x : sbtr[v])sbtr[p].insert(x);
}
}
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,s,q,e;
cin>>n>>s>>q>>e;
vector <int> mag(s),a(n),b(n),c(n);
for(int i=0;i<n-1;i++){
cin>>a[i]>>b[i]>>c[i];
g[a[i]].pb(b[i]);
g[b[i]].pb(a[i]);
}
dfs(e,0);
for(int i=0;i<s;i++){
cin>>mag[i];
}
while(q--){
int ind,x;
cin>>ind>>x;
ind--;
int u=a[ind];
int v=b[ind];
if(d[u]<d[v])swap(u,v);
auto it=lower_bound(all(sbtr[u]),x);
if(it!=sbtr[u].end() && *it==x)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... |