# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968828 | blackslex | Cities (BOI16_cities) | C++17 | 860 ms | 262144 KiB |
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;
using ll = long long;
using pii = pair<ll, ll>;
int n, m, k, x, y;
ll z;
int main() {
scanf("%d %d %d", &n, &k, &m);
vector<int> c(k);
for (auto &e: c) scanf("%d", &e);
vector<vector<ll>> d(n + 5, vector<ll>(n + 5, 1e18));
for (int i = 1; i <= n; i++) d[i][i] = 0;
while (m--) scanf("%d %d %lld", &x, &y, &z), d[x][y] = min(d[x][y], z), d[y][x] = min(d[y][x], z);
for (int l = 1; l <= n; l++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
ll ans = 1e18;
for (int i = 1; i <= n; i++) {
ll cur = 0;
for (int t = 0; t < k; t++) ans += d[i][c[t]];
ans = min(ans, cur);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int msk = 0; msk < (1 << k); msk++) {
ll cur = d[i][j];
for (int t = 0; t < k; t++) {
if (msk & (1 << t)) cur += d[i][c[t]];
else cur += d[j][c[t]];
}
ans = min(ans, cur);
}
}
}
printf("%lld", ans);
}
Compilation message (stderr)
# | 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... |