# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96942 | 2019-02-12T19:52:29 Z | Kastanda | Cities (BOI16_cities) | C++11 | 3199 ms | 85300 KB |
#include<bits/stdc++.h> using namespace std; const int N = 100005, K = 5; int n, m, k, A[K], Pq[N * 30]; bool M[N]; long long dp[1 << K][N]; vector < pair < int , int > > Adj[N]; int main() { scanf("%d%d%d", &n, &k, &m); memset(dp, 63, sizeof(dp)); for (int i = 0; i < k; i++) scanf("%d", &A[i]), dp[1 << i][A[i]] = 0; for (int i = 1; i <= m; i++) { int v, u, w; scanf("%d%d%d", &v, &u, &w); Adj[v].push_back({u, w}); Adj[u].push_back({v, w}); } for (int mask = 1; mask < (1 << k); mask ++) { if (__builtin_popcount(mask) > 1) for (int v = 1; v <= n; v ++) for (int sub = mask; sub; sub = (sub - 1) & mask) if (sub && (sub ^ mask)) for (auto &u : Adj[v]) if (dp[mask][v] > dp[sub][v] + dp[mask ^ sub][u.first] + u.second) dp[mask][v] = dp[sub][v] + dp[mask ^ sub][u.first] + u.second; int l = 0, r = 0; for (int v = 1; v <= n; v ++) Pq[r ++] = v, M[v] = 1; while (r - l) { int v = Pq[l ++]; M[v] = 0; for (auto &u : Adj[v]) if (dp[mask][u.first] > dp[mask][v] + u.second) { dp[mask][u.first] = dp[mask][v] + u.second; if (!M[u.first]) M[u.first] = 1, Pq[r ++] = u.first; } } } return !printf("%lld\n", dp[(1 << k) - 1][A[0]]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 27776 KB | Output is correct |
2 | Correct | 23 ms | 27776 KB | Output is correct |
3 | Correct | 23 ms | 27868 KB | Output is correct |
4 | Correct | 22 ms | 27768 KB | Output is correct |
5 | Correct | 28 ms | 27656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 486 ms | 35544 KB | Output is correct |
2 | Correct | 343 ms | 35280 KB | Output is correct |
3 | Runtime error | 496 ms | 85300 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 27776 KB | Output is correct |
2 | Correct | 24 ms | 27748 KB | Output is correct |
3 | Correct | 26 ms | 28024 KB | Output is correct |
4 | Correct | 25 ms | 27776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 940 ms | 35876 KB | Output is correct |
2 | Correct | 634 ms | 35216 KB | Output is correct |
3 | Runtime error | 308 ms | 85212 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2558 ms | 36156 KB | Output is correct |
2 | Correct | 3199 ms | 36188 KB | Output is correct |
3 | Correct | 1945 ms | 35196 KB | Output is correct |
4 | Runtime error | 275 ms | 85240 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |