# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96937 | 2019-02-12T19:42:16 Z | Kastanda | Cities (BOI16_cities) | C++11 | 4274 ms | 42572 KB |
#include<bits/stdc++.h> using namespace std; const int N = 100005, K = 5; int n, m, k, A[K]; 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}); } priority_queue < pair < long long , int > > Pq; 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; for (int v = 1; v <= n; v ++) Pq.push({-dp[mask][v], v}); while (Pq.size()) { int v = Pq.top().second; long long d = -Pq.top().first; Pq.pop(); if (d > dp[mask][v]) continue; for (auto &u : Adj[v]) if (dp[mask][u.first] > dp[mask][v] + u.second) dp[mask][u.first] = dp[mask][v] + u.second, Pq.push({-dp[mask][u.first], u.first}); } } return !printf("%lld\n", dp[(1 << k) - 1][A[0]]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 27896 KB | Output is correct |
2 | Correct | 21 ms | 27776 KB | Output is correct |
3 | Correct | 21 ms | 27776 KB | Output is correct |
4 | Correct | 21 ms | 27776 KB | Output is correct |
5 | Correct | 26 ms | 27768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 864 ms | 42572 KB | Output is correct |
2 | Correct | 1008 ms | 42100 KB | Output is correct |
3 | Correct | 563 ms | 35184 KB | Output is correct |
4 | Correct | 131 ms | 35704 KB | Output is correct |
5 | Correct | 571 ms | 42536 KB | Output is correct |
6 | Correct | 118 ms | 35936 KB | Output is correct |
7 | Correct | 29 ms | 27896 KB | Output is correct |
8 | Correct | 25 ms | 27896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 27920 KB | Output is correct |
2 | Correct | 28 ms | 27904 KB | Output is correct |
3 | Correct | 28 ms | 27896 KB | Output is correct |
4 | Correct | 27 ms | 27896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1753 ms | 42428 KB | Output is correct |
2 | Correct | 1893 ms | 41952 KB | Output is correct |
3 | Correct | 1263 ms | 35180 KB | Output is correct |
4 | Correct | 1046 ms | 40012 KB | Output is correct |
5 | Correct | 306 ms | 37496 KB | Output is correct |
6 | Correct | 158 ms | 37496 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4274 ms | 42568 KB | Output is correct |
2 | Correct | 3597 ms | 42460 KB | Output is correct |
3 | Correct | 3858 ms | 41956 KB | Output is correct |
4 | Correct | 3230 ms | 35332 KB | Output is correct |
5 | Correct | 2097 ms | 39824 KB | Output is correct |
6 | Correct | 534 ms | 37360 KB | Output is correct |
7 | Correct | 236 ms | 37624 KB | Output is correct |