# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
208588 | 2020-03-11T17:44:57 Z | DodgeBallMan | Cities (BOI16_cities) | C++14 | 4224 ms | 116968 KB |
#include <bits/stdc++.h> #define long long long #define pii pair<long, long> #define x first #define y second using namespace std; const int N = 1e5+5; int n, k, m, id[N]; long cost[N][1 << 5]; vector<pii> g[N]; vector<int> vbit[6]; int main() { memset(id, -1, sizeof id); fill_n(cost[0], N * (1 << 5), 1e18); scanf("%d %d %d", &n, &k, &m); for(int i = 0, a; i < k; i++) { scanf("%d", &a); id[a - 1] = i; } for(int i = 1, a, b, c; i <= m; i++) { scanf("%d %d %d", &a, &b, &c); g[a-1].emplace_back(b-1, c); g[b-1].emplace_back(a-1, c); } for(int i = 1; i < (1 << k); i++) vbit[__builtin_popcount(i)].emplace_back(i); for(int step = 1; step <= k; step++) { priority_queue<pair<long, pii> > Q; if(step == 1) { for(int i = 0; i < n; i++) if(id[i] != -1) { cost[i][1 << id[i]] = 0; Q.emplace(-cost[i][1 << id[i]], make_pair(i, 1ll << id[i])); } } else { for(int i = 0; i < n; i++) for(int x : vbit[step]) { for(int y = 0; y < (1 << k); y++) { if((x & y) != y) continue; cost[i][x] = min(cost[i][x], cost[i][y] + cost[i][x ^ y]); } Q.emplace(-cost[i][x], make_pair(i, x)); } } while(!Q.empty()) { auto now = Q.top(); Q.pop(); if(cost[now.y.x][now.y.y] != -now.x) continue; long c = -now.x; int u = now.y.x, bit = now.y.y; for(pii v : g[u]) if(cost[v.x][bit] > c + v.y) { cost[v.x][bit] = c + v.y; Q.emplace(-cost[v.x][bit], make_pair(v.x, bit)); } } } long ans = 1e18; for(int i = 0; i < n; i++) ans = min(ans, cost[i][(1 << k) - 1]); printf("%lld\n", ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 28156 KB | Output is correct |
2 | Correct | 17 ms | 28152 KB | Output is correct |
3 | Correct | 17 ms | 28152 KB | Output is correct |
4 | Correct | 17 ms | 28156 KB | Output is correct |
5 | Correct | 17 ms | 28152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 887 ms | 56884 KB | Output is correct |
2 | Correct | 885 ms | 56080 KB | Output is correct |
3 | Correct | 494 ms | 45788 KB | Output is correct |
4 | Correct | 117 ms | 37420 KB | Output is correct |
5 | Correct | 451 ms | 47708 KB | Output is correct |
6 | Correct | 111 ms | 37316 KB | Output is correct |
7 | Correct | 21 ms | 28408 KB | Output is correct |
8 | Correct | 19 ms | 28280 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 28580 KB | Output is correct |
2 | Correct | 23 ms | 28516 KB | Output is correct |
3 | Correct | 22 ms | 28472 KB | Output is correct |
4 | Correct | 21 ms | 28472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1874 ms | 63488 KB | Output is correct |
2 | Correct | 1894 ms | 77116 KB | Output is correct |
3 | Correct | 1223 ms | 58056 KB | Output is correct |
4 | Correct | 1056 ms | 57696 KB | Output is correct |
5 | Correct | 277 ms | 42036 KB | Output is correct |
6 | Correct | 123 ms | 39632 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4142 ms | 112664 KB | Output is correct |
2 | Correct | 4207 ms | 116968 KB | Output is correct |
3 | Correct | 4224 ms | 115752 KB | Output is correct |
4 | Correct | 2788 ms | 83716 KB | Output is correct |
5 | Correct | 2245 ms | 82524 KB | Output is correct |
6 | Correct | 437 ms | 50364 KB | Output is correct |
7 | Correct | 143 ms | 43660 KB | Output is correct |