# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
969402 | 2024-04-25T06:09:24 Z | blackslex | Cities (BOI16_cities) | C++17 | 713 ms | 35692 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; int n, m, k, x, y, z; int main() { scanf("%d %d %d", &n, &k, &m); vector<int> c(k); vector<vector<pii>> v(n + 5, vector<pii>()); for (auto &e: c) scanf("%d", &e); while (m--) scanf("%d %d %d", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z); vector<vector<int>> dp((1 << k) + 5, vector<int>(n + 5, 1e9)); for (int i = 0; i < k; i++) dp[1 << i][c[i]] = 0; for (int i = 1; i < (1 << k); i++) { for (int j = i; j; j = (j - 1) & i) { for (int r = 1; r <= n; r++) { dp[i][r] = min(dp[i][r], dp[j][r] + dp[i ^ j][r]); } } auto dijk = [&] (vector<int> &curd) { priority_queue<pii, vector<pii>, greater<pii>> pq; for (int j = 1; j <= n; j++) pq.emplace(curd[j], j); while (!pq.empty()) { auto [nd, nn] = pq.top(); pq.pop(); for (auto &[tn, td]: v[nn]) if (curd[tn] > curd[nn] + td) pq.emplace(curd[tn] = curd[nn] + td, tn); } }; dijk(dp[i]); } printf("%d", *min_element(dp[(1 << k) - 1].begin(), dp[(1 << k) - 1].end())); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 248 ms | 26232 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 604 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 369 ms | 29800 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 713 ms | 35692 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |