# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96230 | 2019-02-07T11:12:37 Z | ics0503 | Cities (BOI16_cities) | C++17 | 6000 ms | 44144 KB |
#include<stdio.h> #include<vector> #include<queue> using namespace std; struct xy { long long x, y; bool operator<(const xy p)const { return x < p.x; } }; vector<xy>edge[121212]; priority_queue<xy>H; long long D[1 << 5][121212], L[6]; long long pls(long long a, long long b) { if (a == -1)return -1; if (b == -1)return -1; return a + b; } long long min(long long a, long long b) { if (a == -1)return b; if (b == -1)return a; if (a < b)return a; return b;} int main() { long long n, m, k; scanf("%lld%lld%lld", &n, &k, &m); long long i, j; for (i = 0; i < k; i++)scanf("%lld", &L[i]); for (i = 0; i < m; i++) { long long s, e, w; scanf("%lld%lld%lld", &s, &e, &w); edge[s].push_back({ e,w }); edge[e].push_back({ s,w }); } for (i = 0; i < (1 << k); i++)for (j = 1; j <= n; j++)D[i][j] = -1; for (i = 0; i < k; i++)D[(1 << i)][L[i]] = 0; for (i = 1; i < (1 << k); i++) { for (j = 1; j <= n; j++) for (long long p = 0; p < i; p++) if ((i | p) == i)D[i][j] = min(D[i][j], pls(D[p][j], D[i^p][j])); for (j = 1; j <= n; j++) if (D[i][j] != -1)H.push({ D[i][j],j }); while (!H.empty()) { xy now = H.top(); H.pop(); if (now.x != D[i][now.y])continue; for (j = 0; j < edge[now.y].size(); j++) { long long nxt = edge[now.y][j].x, w = edge[now.y][j].y; if (D[i][nxt] == -1 || D[i][nxt] > D[i][now.y] + w) { D[i][nxt] = D[i][now.y] + w; H.push({ D[i][nxt], nxt }); } } } } long long ans = -1; for (i = 1; i <= n; i++)ans = min(ans, D[(1 << k) - 1][i]); printf("%lld", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3232 KB | Output is correct |
2 | Correct | 4 ms | 3192 KB | Output is correct |
3 | Correct | 3 ms | 3192 KB | Output is correct |
4 | Correct | 4 ms | 3320 KB | Output is correct |
5 | Correct | 4 ms | 3320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6012 ms | 25320 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 76 ms | 3576 KB | Output is correct |
2 | Correct | 20 ms | 3576 KB | Output is correct |
3 | Correct | 39 ms | 3448 KB | Output is correct |
4 | Correct | 35 ms | 3448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6100 ms | 31472 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 6008 ms | 44144 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |