Submission #915565

#TimeUsernameProblemLanguageResultExecution timeMemory
915565AndrijaMValley (BOI19_valley)C++14
0 / 100
162 ms15976 KiB
#include <bits/stdc++.h> using namespace std; const long long maxn=1e5+10; const long long logn=25; const long long mod=1e9+7; int n,s,q,e; vector<pair<int,int>>g[maxn]; set<int>ins; vector<pair<int,int>>pr; struct node { int idx; int dis; node(){} node(int _idx,int _dis) { idx=_idx; dis=_dis; } bool operator <(const node &tmp)const { return dis>tmp.dis; } }; int main() { cin>>n>>s>>q>>e; for(int i=0;i<n-1;i++) { int a,b,c; cin>>a>>b>>c; a--;b--; g[a].push_back({b,c}); g[b].push_back({a,c}); pr.push_back({a,b}); } for(int i=0;i<s;i++) { int pom; cin>>pom; ins.insert(pom-1); } while(q--) { int idxe,st; cin>>idxe>>st; idxe--; st--; int n1=pr[idxe].first; int n2=pr[idxe].second; if(n<1100) { ///kolku e odalecen od S priority_queue<node>Q; Q.push(node(st,0)); int d[n]; for(int pi=0;pi<n;pi++) { d[pi]=2e9; } d[st]=0; bool ok=false; while(!Q.empty()) { node teme=Q.top();Q.pop(); if(teme.idx==e) { cout<<"escaped"<<endl; ok=true; break; } for(auto ax:g[teme.idx]) { if((teme.idx==n1 && ax.first==n2) || (teme.idx==n2 && ax.first==n1)) { continue; } if(teme.dis+ax.second<d[ax.first]) { d[ax.first]=teme.dis+ax.second; Q.push(node(ax.first,d[ax.first])); } } } int ans=2e9; for(auto pom:ins) { ans=min(ans, d[pom]); } if(!ok) { if(ans!=2e9) cout<<ans<<endl; else { cout<<"oo"<<endl; } } } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...