Submission #964763

#TimeUsernameProblemLanguageResultExecution timeMemory
964763AiperiiiEvacuation plan (IZhO18_plan)C++14
23 / 100
626 ms42188 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; g[0].pb({x,0}); g[x].pb({0,0}); } find(0,n); for(int i=1;i<=n;i++){ if(d[i]==1e18)d[i]=0; } int q; cin>>q; while(q--){ int s,t; cin>>s>>t; cout<<min(d[s],d[t])<<"\n"; } } /* 9 12 1 9 4 1 2 5 2 3 7 2 4 3 4 3 6 3 6 4 8 7 10 6 7 5 5 8 1 9 5 7 5 4 12 6 8 2 2 4 7 */
#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...