#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
cities.cpp: In function 'int main()':
cities.cpp:16:8: warning: unused variable 'dist' [-Wunused-variable]
16 | ll dist[n+5],p[k+5];
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
21156 KB |
Output is correct |
2 |
Correct |
248 ms |
21692 KB |
Output is correct |
3 |
Correct |
59 ms |
11612 KB |
Output is correct |
4 |
Correct |
47 ms |
12628 KB |
Output is correct |
5 |
Correct |
177 ms |
21072 KB |
Output is correct |
6 |
Correct |
45 ms |
12636 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
284 ms |
21072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
345 ms |
21396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |