#include <bits/stdc++.h>
#define int long long
using namespace std;
int a, b, c;
int t[10000];
vector<pair<int, int>> z[1000005];
int cnt[100005][270];
int bruh = 1e18;
void dijkstra() {
for (int i = 1; i <= a; i++) {
for (int j = 0; j < (1 << b); j++) {
cnt[i][j] = bruh;
}
}
for (int i = 0; i < b; i++) {
cnt[t[i]][1 << i] = 0;
}
for (int mask = 0; mask < (1 << b); mask++) {
for (int i = 1; i <= a; i++) {
for (int submask = (mask - 1) & mask; submask; submask = (submask - 1) & mask) {
cnt[i][mask] = min(cnt[i][mask], cnt[i][submask] + cnt[i][mask ^ submask]);
}
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (int i = 1; i <= a; i++) {
if (cnt[i][mask] != bruh) {
q.push({cnt[i][mask], i});
}
}
while (!q.empty()) {
auto [val, u] = q.top(); q.pop();
if (val > cnt[u][mask]) continue;
for (auto [v, w] : z[u]) {
if (cnt[v][mask] > val + w) {
cnt[v][mask] = val + w;
q.push({cnt[v][mask], v});
}
}
}
}
int res = bruh;
for (int i = 1; i <= a; i++) {
res = min(res, cnt[i][(1 << b) - 1]);
}
cout << res << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b >> c;
for (int i = 0; i < b; i++) {
cin >> t[i];
}
for (int i = 1; i <= c; i++) {
int x, y, t;
cin >> x >> y >> t;
z[x].push_back({y, t});
z[y].push_back({x, t});
}
dijkstra();
return 0;
}
# | 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... |