Submission #535090

#TimeUsernameProblemLanguageResultExecution timeMemory
535090__VariattoValley (BOI19_valley)C++17
23 / 100
145 ms17604 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define ll long long const int MAX=1e5+10; const ll MAXV=1e16; int n, s, q, e, a[MAX], b[MAX], w; bool sk[MAX]; vector<pair<int,int>>g[MAX]; int czas, pre[MAX], maxiPre[MAX]; ll naj[MAX], gle[MAX]; void dfs(int v, int oj){ pre[v]=++czas; naj[v]=MAXV; if(sk[v]) naj[v]=0; for(auto s:g[v]){ if(s.fi!=oj){ gle[s.fi]=gle[v]+(ll)s.se; dfs(s.fi, v); naj[v]=min(naj[v], naj[s.fi]+(ll)s.se); } } maxiPre[v]=czas; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin>>n>>s>>q>>e; for(int i=1; i<=n-1; i++){ cin>>a[i]>>b[i]>>w; g[a[i]].pb({b[i], w}), g[b[i]].pb({a[i], w}); } for(int i=1; i<=s; i++){ int c; cin>>c; sk[c]=true; } dfs(e, e); while(q--){ int x, y; cin>>x>>y; int u1=a[x], u2=b[x]; if(pre[u1]>pre[u2]) swap(u1, u2); if(pre[u2]>pre[y] || maxiPre[u2]<pre[y]){ cout<<"escaped\n"; continue; } if(naj[u2]==MAXV){ cout<<"oo\n"; continue; } ll odl=min(naj[y], naj[u2]+gle[y]-gle[u2]); cout<<odl<<"\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...