#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
int n,k,m;
vector<int> s;
vector<pair<int,int>> adj[N];
vector dis(4,vector<int>(N,INF));
void dijk(int s,vector<int> &dis){
dis[s]=0;
priority_queue<pair<int,int>> pq;
pq.push({0,s});
while(pq.size()){
auto [dis1,a]=pq.top();
pq.pop();
dis1=-dis1;
if(dis1!=dis[a])continue;
for(auto [c,d]:adj[a]){
int cost=dis1+d;
if(dis[c]>cost){
dis[c]=cost;
pq.push({-dis[c],c});
}
}
}
}
int32_t main() {
LCBorz;
cin>>n>>k>>m;
for(int i=0;i<k;i++){
int p;cin>>p;
s.push_back(p);
}
for(int i=0;i<m;i++){
int a,b,c;cin>>a>>b>>c;
adj[a].push_back({b,c});
adj[b].push_back({a,c});
}
for(int i=0;i<k;i++){
dijk(s[i],dis[i]);
}
int ans=INF;
for(int i=1;i<=n;i++){
int cost=0;
for(int j=0;j<k;j++){
cost+=dis[j][i];
}
ans=min(ans,cost);
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12892 KB |
Output is correct |
2 |
Correct |
5 ms |
12892 KB |
Output is correct |
3 |
Correct |
5 ms |
12904 KB |
Output is correct |
4 |
Incorrect |
6 ms |
12892 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
23632 KB |
Output is correct |
2 |
Correct |
156 ms |
24180 KB |
Output is correct |
3 |
Correct |
56 ms |
16436 KB |
Output is correct |
4 |
Correct |
54 ms |
20316 KB |
Output is correct |
5 |
Correct |
153 ms |
23424 KB |
Output is correct |
6 |
Correct |
66 ms |
23864 KB |
Output is correct |
7 |
Correct |
6 ms |
12892 KB |
Output is correct |
8 |
Correct |
5 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
214 ms |
23860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
256 ms |
47568 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |