# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91015 | EntityIT | Cities (BOI16_cities) | C++14 | 2784 ms | 104820 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;
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> ii;
typedef pair<long long, int> lli;
const int N = 1e5 + 5;
const long long inf = (long long)1e18 + 123;
int n, K, m;
long long d[1 << 5][N];
vector<int> important;
vector<ii> gr[N];
int main () {
// freopen("test.INP", "r", stdin);
for (int mask = 0; mask < (1 << 5); ++mask) {
for (int i = 0; i < N; ++i) d[mask][i] = inf;
}
scanf("%d %d %d", &n, &K, &m);
important.assign(K, 0);
for (int i = 0; i < K; ++i) {
int u; scanf("%d", &u);
important[i] = u;
d[1 << i][u] = 0;
}
while (m --) {
int u, v, w; scanf("%d %d %d", &u, &v, &w);
gr[u].pb(ii(v, w) );
gr[v].pb(ii(u, w) );
}
for (int mask = 1; mask < (1 << K); ++mask) {
for (int subMask = mask; subMask; subMask = (subMask - 1) & mask) {
for (int u = 1; u <= n; ++u) d[mask][u] = min(d[mask][u], d[subMask][u] + d[mask ^ subMask][u]);
}
priority_queue<lli, vector<lli>, greater<lli> > pq;
for (int u = 1; u <= n; ++u) pq.push(lli(d[mask][u], u) );
while (!pq.empty() ) {
lli tmp = pq.top(); pq.pop();
int u = tmp.se;
if (tmp.fi > d[mask][u]) continue ;
for (ii _ : gr[u]) {
int v = _.fi, w = _.se;
if (d[mask][v] > d[mask][u] + w) {
d[mask][v] = d[mask][u] + w;
pq.push(lli(d[mask][v], v) );
}
}
}
}
long long ans = inf;
for (int u = 1; u <= n; ++u) ans = min(ans, d[(1 << K) - 1][u]);
printf("%lld", ans);
return 0;
}
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... |