# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84250 | 2018-11-14T03:08:02 Z | Vinhspm | Cities (BOI16_cities) | C++14 | 6000 ms | 48740 KB |
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define FOR(a, b, c) for(int a = b; a <= c; ++a) #define pb push_back #define ll long long const int N = 1e5 + 10; const ll oo = 1e18; typedef pair<int, int> ii; typedef pair<ll, ii> pii; int n, k, m; int pos[N]; bool inqueue[N][(1 << 5)]; ll f[N][(1 << 5)], ans = oo; vector<ii> vi[N]; void upd(ll &x, ll y) { x = min(x, y); } void solve() { FOR(i, 1, n) FOR(j, 0, (1 << k) - 1) f[i][j] = oo; queue<ii> pq; FOR(i, 1, n) { int mask = 0; if(pos[i]) mask = (1 << (pos[i] - 1)); f[i][mask] = 0ll; pq.push(ii(i, mask)); inqueue[i][mask] = true; } while(!pq.empty()) { int u = pq.front().fi, mask = pq.front().se; pq.pop(); inqueue[u][mask] = false; if(mask == (1 << k) - 1) upd(ans, f[u][mask]); if(ans <= f[u][mask]) continue; //cout << u << ' ' << mask << '\n'; for(auto v: vi[u]) { for(int t = 0; t < (1 << k); ++t) if(!(mask & t)) { int nex = (mask | t); if(f[u][mask] + 1ll * v.se + f[v.fi][t] >= ans) continue; if(f[v.fi][nex] > f[u][mask] + 1ll * v.se + f[v.fi][t]) { f[v.fi][nex] = f[u][mask] + 1ll * v.se + f[v.fi][t]; if(!inqueue[v.fi][nex]) { pq.push(ii(v.fi, nex)); inqueue[v.fi][nex] = true; } } } } } } signed main() { //freopen("test.inp", "r", stdin); scanf("%d%d%d", &n, &k, &m); FOR(i, 1, k) { int x; scanf("%d", &x); pos[x] = i; } FOR(i, 1, m) { int u, v, c; scanf("%d%d%d", &u, &v, &c); vi[u].pb(ii(v, c)); vi[v].pb(ii(u, c)); } solve(); printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2680 KB | Output is correct |
2 | Correct | 4 ms | 2804 KB | Output is correct |
3 | Correct | 4 ms | 2880 KB | Output is correct |
4 | Correct | 4 ms | 2880 KB | Output is correct |
5 | Correct | 4 ms | 2916 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 726 ms | 38592 KB | Output is correct |
2 | Correct | 766 ms | 38752 KB | Output is correct |
3 | Correct | 163 ms | 38752 KB | Output is correct |
4 | Correct | 201 ms | 38752 KB | Output is correct |
5 | Correct | 309 ms | 38752 KB | Output is correct |
6 | Correct | 106 ms | 38752 KB | Output is correct |
7 | Correct | 7 ms | 38752 KB | Output is correct |
8 | Correct | 5 ms | 38752 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 38752 KB | Output is correct |
2 | Correct | 12 ms | 38752 KB | Output is correct |
3 | Correct | 6 ms | 38752 KB | Output is correct |
4 | Correct | 15 ms | 38752 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3100 ms | 42048 KB | Output is correct |
2 | Correct | 2045 ms | 43392 KB | Output is correct |
3 | Correct | 524 ms | 43392 KB | Output is correct |
4 | Correct | 2007 ms | 43392 KB | Output is correct |
5 | Correct | 674 ms | 43392 KB | Output is correct |
6 | Correct | 536 ms | 43392 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6051 ms | 48740 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |