Submission #1021829

#TimeUsernameProblemLanguageResultExecution timeMemory
1021829m5588ohammedValley (BOI19_valley)C++14
0 / 100
84 ms14016 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" int n,S,E,q,U,V,x,l; vector <array<int,2>> v[100001],edges; priority_queue <array<int,2>> qu; int dis[100001],shops[100001]; void dij(){ for(int i=1;i<=n;i++) dis[i]=1e15; dis[x]=0; qu.push({0,x}); while(!qu.empty()){ auto [mydis,i]=qu.top(); mydis*=-1; qu.pop(); if(mydis>dis[i]) continue; for(auto [j,w]:v[i]){ if((i==U&&j==V)||(i==V&&j==U)) continue; if(dis[j]>mydis+w){ dis[j]=mydis+w; qu.push({dis[j]*-1,j}); } } } return; } void calc1(){ while(q--){ cin>>l>>x; U=edges[l-1][0]; V=edges[l-1][1]; dij(); if(dis[E]!=1e15){ cout<<"escaped"<<endl;continue;} int mn=1e15; for(int i=0;i<S;i++) mn=min(mn,dis[shops[i]]); if(mn==1e15) cout<<"oo"<<endl; else cout<<mn<<endl; } } signed main() { cin>>n>>S>>q>>E; for(int i=0;i<n-1;i++){ int a,b,c; cin>>a>>b>>c; v[a].push_back({b,c}); v[b].push_back({a,c}); edges.push_back({a,b}); } for(int i=0;i<S;i++) cin>>shops[i]; if(n<=1000&&q<=1000) calc1(); return 0; }

Compilation message (stderr)

valley.cpp: In function 'void dij()':
valley.cpp:14:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |         auto [mydis,i]=qu.top();
      |              ^
valley.cpp:18:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   18 |         for(auto [j,w]:v[i]){
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...