#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define pii array<int, 2>
#define pli pair<ll, int>
const int N = 1e5 + 4;
const ll INF = 4ll * INT_MAX * N;
int n, k, m;
vector<int> imp;
vector<pii> g[N];
ll d[5][N];
bool vis[N];
priority_queue<pli> pq;
void dijkstra(int idx) {
for (int i = 0; i < n; ++i) {
d[idx][i] = INF;
vis[i] = false;
}
pq.push({0, imp[idx]});
d[idx][imp[idx]] = 0;
while (pq.size() > 0) {
int v = pq.top().S;
pq.pop();
if (vis[v] == true) {
continue;
}
vis[v] = true;
for (auto [u, w] : g[v]) {
if (vis[u] == false && d[idx][v] + w < d[idx][u]) {
d[idx][u] = d[idx][v] + w;
pq.push({d[idx][u], u});
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> m;
for (int i = 0; i < k; ++i) {
int v;
cin >> v; --v;
imp.pb(v);
}
for (int i = 0; i < m; ++i) {
int v, u, w;
cin >> v >> u >> w;
--v; --u;
g[v].pb({u, w});
g[u].pb({v, w});
}
for (int i = 0; i < k; ++i) {
dijkstra(i);
}
ll ans = INF;
for (int v = 0; v < n; ++v) {
ll cand = 0;
for (int i = 0; i < k; ++i) {
cand += d[i][v];
}
ans = min(ans, cand);
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
108 ms |
14036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
127 ms |
14028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
183 ms |
14036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |