Submission #964760

#TimeUsernameProblemLanguageResultExecution timeMemory
964760AiperiiiEvacuation plan (IZhO18_plan)C++14
10 / 100
4103 ms20468 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 <pair <int,int > > g[N]; int no[N],d[N]; int find(int s,int n){ set <pair <int,int> > st; st.insert({0,s}); for(int i=1;i<=n;i++)d[i]=1e18; d[s]=0; while(!st.empty()){ int v=st.begin()->ss; st.erase(st.begin()); for(auto to : g[v]){ if(d[to.ff]>d[v]+to.ss){ st.erase({d[to.ff],to.ff}); d[to.ff]=d[v]+to.ss; st.insert({d[to.ff],to.ff}); } } } int mn=1e18; for(int i=1;i<=n;i++){ if(no[i]){ mn=min(mn,d[i]); } } if(mn==1e18)mn=0; return mn; } signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int u,v,w; cin>>u>>v>>w; g[u].pb({v,w}); g[v].pb({u,w}); } int k; cin>>k; for(int i=0;i<k;i++){ int x; cin>>x; no[x]=1; } int q; cin>>q; while(q--){ int s,t; cin>>s>>t; cout<<min(find(s,n),find(t,n))<<"\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...
#Verdict Execution timeMemoryGrader output
Fetching results...