Submission #922991

#TimeUsernameProblemLanguageResultExecution timeMemory
922991AiperiiiValley (BOI19_valley)C++14
23 / 100
212 ms33444 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]; int d[N],par[N],jmp[N][20]; void dfs(int v,int p){ par[v]=p; for(auto to : g[v]){ if(to!=p){ d[to]=d[v]+1; dfs(to,v); } } } int lca(int a,int b){ if(d[a]<d[b])swap(a,b); for(int i=19;i>=0;i--){ if(d[jmp[a][i]]>=d[b]){ a=jmp[a][i]; } } if(a==b)return a; for(int i=19;i>=0;i--){ if(jmp[a][i]!=jmp[b][i]){ a=jmp[a][i]; b=jmp[b][i]; } } return par[a]; } 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); par[e]=e; for(int i=1;i<=n;i++){ jmp[i][0]=par[i]; } for(int j=1;j<20;j++){ for(int i=1;i<=n;i++){ jmp[i][j]=jmp[jmp[i][j-1]][j-1]; } } 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); if(lca(u,x)==u)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...