This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,k,m;
cin>>n>>k>>m;
ll dist[n+5],p[k+5];
for(ll i=1;i<=k;i++){
cin>>p[i];
}
vector<pair<ll,ll>>adj[n+5];
for(ll i=1;i<=m;i++){
ll a,b,c;
cin>>a>>b>>c;
adj[a].pb({b,c});
adj[b].pb({a,c});
}
vector<ll>tot(n+5,0);
for(ll i=1;i<=k;i++){
vector<ll>dist(n+5,1e18);
set<pair<ll,ll>>st;
st.insert({0,p[i]});
dist[p[i]]=0;
while(!st.empty()){
auto [d,j]=*st.begin();
st.erase(st.begin());
for(auto [b,c]:adj[j]){
if(dist[j]+c<dist[b]){
if(dist[b]<1e18){
st.erase({dist[b],b});
}
dist[b]=dist[j]+c;
st.insert({dist[b],b});
}
}
}
for(ll j=1;j<=n;j++){
tot[j]+=dist[j];
}
}
ll ans=1e18;
for(ll i=1;i<=n;i++){
ans=min(ans,tot[i]);
}
cout<<ans;
}
Compilation message (stderr)
cities.cpp: In function 'int main()':
cities.cpp:16:8: warning: unused variable 'dist' [-Wunused-variable]
16 | ll dist[n+5],p[k+5];
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |