# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
128302 | IOrtroiii | Cities (BOI16_cities) | C++14 | 3084 ms | 46860 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;
const ll inf = 1e18;
const int N = 200200;
ll d[1 << 5][N];
vector<pair<int, int>> g[N];
int main() {
int n, k, m;
scanf("%d %d %d", &n, &k, &m);
for (int i = 1; i < (1 << k); ++i) {
for (int j = 1; j <= n; ++j) {
d[i][j] = inf;
}
}
for (int i = 0; i < k; ++i) {
int v;
scanf("%d", &v);
d[1 << i][v] = 0;
}
for (int i = 1; i <= m; ++i) {
int u, v, w;
scanf("%d %d %d", &u, &v, &w);
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
for (int i = 1; i < (1 << k); ++i) {
for (int j = i; ; j = (j - 1) & i) {
for (int u = 1; u <= n; ++u) {
d[i][u] = min(d[i][u], d[j][u] + d[i ^ j][u]);
}
if (j == 0) {
break;
}
}
priority_queue<pair<ll, int>> q;
for (int u = 1; u <= n; ++u) {
q.emplace(-d[i][u], u);
}
while (!q.empty()) {
ll du = -q.top().first;
int u = q.top().second;
q.pop();
if (du != d[i][u]) {
continue;
}
for (auto e : g[u]) {
int v, w;
tie(v, w) = e;
if (d[i][v] > d[i][u] + w) {
d[i][v] = d[i][u] + w;
q.emplace(-d[i][v], v);
}
}
}
}
printf("%lld\n", *min_element(d[(1 << k) - 1] + 1, d[(1 << k) - 1] + n));
}
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... |