# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
84253 | 2018-11-14T03:20:50 Z | Vinhspm | Cities (BOI16_cities) | C++14 | 6000 ms | 50284 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") 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(ans <= f[u][mask]) continue; //cout << u << ' ' << mask << '\n'; for(auto v: vi[u]) { if(f[u][mask] + v.se >= ans) continue; if(f[v.fi][mask] > f[u][mask] + v.se) { f[v.fi][mask] = f[u][mask] + v.se; if(!inqueue[v.fi][mask]) { pq.push(ii(v.fi, mask)); } } } 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; } if(nex == (1 << k) - 1) upd(ans, f[v.fi][nex]); } } } } } 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 | 2680 KB | Output is correct |
3 | Correct | 4 ms | 2840 KB | Output is correct |
4 | Correct | 4 ms | 2916 KB | Output is correct |
5 | Correct | 5 ms | 2916 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 796 ms | 39024 KB | Output is correct |
2 | Correct | 972 ms | 39404 KB | Output is correct |
3 | Correct | 185 ms | 39404 KB | Output is correct |
4 | Correct | 288 ms | 39404 KB | Output is correct |
5 | Correct | 361 ms | 39404 KB | Output is correct |
6 | Correct | 123 ms | 39404 KB | Output is correct |
7 | Correct | 8 ms | 39404 KB | Output is correct |
8 | Correct | 6 ms | 39404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 39404 KB | Output is correct |
2 | Correct | 14 ms | 39404 KB | Output is correct |
3 | Correct | 6 ms | 39404 KB | Output is correct |
4 | Correct | 14 ms | 39404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3007 ms | 43516 KB | Output is correct |
2 | Correct | 3186 ms | 44556 KB | Output is correct |
3 | Correct | 507 ms | 44556 KB | Output is correct |
4 | Correct | 2446 ms | 44556 KB | Output is correct |
5 | Correct | 1059 ms | 44556 KB | Output is correct |
6 | Correct | 840 ms | 44556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6099 ms | 50284 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |