# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37330 | 2017-12-24T09:31:52 Z | szawinis | Cities (BOI16_cities) | C++14 | 3069 ms | 41916 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pli; const int N = 1e5+1; const ll INF = 1e17+1; int n, k, m; bool mark[N]; vector<int> s; vector<pair<int,int> > g[N]; ll ans = INF, dp[1 << 5][N]; priority_queue<pli, vector<pli>, greater<pli> > pq; int main() { scanf("%d %d %d", &n, &k, &m); for(int i = 0, v; i < k; i++) { scanf("%d", &v); s.push_back(v-1); } for(int i = 0, u, v, w; i < m; i++) { scanf("%d %d %d", &u, &v, &w); g[u-1].emplace_back(v-1, w); g[v-1].emplace_back(u-1, w); } for(int mask = 1; mask < 1 << k; mask++) { for(int v = 0; v < n; v++) dp[mask][v] = INF; } for(int i = 0; i < k; i++) dp[1 << i][s[i]] = 0; for(int mask = 1; mask < 1 << k; mask++) { for(int prev_mask1 = 1; prev_mask1 < mask; prev_mask1++) { int prev_mask2 = prev_mask1 ^ mask; if((prev_mask1 | mask) != mask || prev_mask2 > prev_mask1) continue; for(int v = 0; v < n; v++) dp[mask][v] = min(dp[prev_mask1][v] + dp[prev_mask2][v], dp[mask][v]); } for(int v = 0; v < n; v++) if(dp[mask][v] < INF) pq.emplace(dp[mask][v], v); fill(mark, mark+n, 0); while(!pq.empty()) { int u = pq.top().second; pq.pop(); if(mark[u]) continue; mark[u] = true; for(auto p: g[u]) if(dp[mask][u] + p.second < dp[mask][p.first]) { dp[mask][p.first] = dp[mask][u] + p.second; pq.emplace(dp[mask][p.first], p.first); } } } ll ans = INF; for(int v = 0; v < n; v++) ans = min(dp[(1 << k)-1][v], ans); printf("%lld", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 29460 KB | Output is correct |
2 | Correct | 0 ms | 29460 KB | Output is correct |
3 | Correct | 0 ms | 29460 KB | Output is correct |
4 | Correct | 0 ms | 29460 KB | Output is correct |
5 | Correct | 0 ms | 29460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 739 ms | 41916 KB | Output is correct |
2 | Correct | 733 ms | 41844 KB | Output is correct |
3 | Correct | 466 ms | 35740 KB | Output is correct |
4 | Correct | 136 ms | 33996 KB | Output is correct |
5 | Correct | 443 ms | 41908 KB | Output is correct |
6 | Correct | 149 ms | 34084 KB | Output is correct |
7 | Correct | 0 ms | 29592 KB | Output is correct |
8 | Correct | 0 ms | 29592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 29592 KB | Output is correct |
2 | Correct | 3 ms | 29592 KB | Output is correct |
3 | Correct | 6 ms | 29600 KB | Output is correct |
4 | Correct | 3 ms | 29592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1423 ms | 41908 KB | Output is correct |
2 | Correct | 1513 ms | 41700 KB | Output is correct |
3 | Correct | 1116 ms | 35740 KB | Output is correct |
4 | Correct | 913 ms | 38344 KB | Output is correct |
5 | Correct | 299 ms | 35484 KB | Output is correct |
6 | Correct | 113 ms | 35780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3069 ms | 41904 KB | Output is correct |
2 | Correct | 2913 ms | 41904 KB | Output is correct |
3 | Correct | 2696 ms | 41748 KB | Output is correct |
4 | Correct | 2213 ms | 35740 KB | Output is correct |
5 | Correct | 1596 ms | 38344 KB | Output is correct |
6 | Correct | 393 ms | 35484 KB | Output is correct |
7 | Correct | 136 ms | 35636 KB | Output is correct |