Submission #922986

#TimeUsernameProblemLanguageResultExecution timeMemory
922986AiperiiiValley (BOI19_valley)C++14
0 / 100
501 ms262144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...