# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
969404 | 2024-04-25T06:10:21 Z | blackslex | Cities (BOI16_cities) | C++17 | 2229 ms | 54912 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; int n, m, k, x, y; ll 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 %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z); vector<vector<ll>> dp((1 << k) + 5, vector<ll>(n + 5, 1e18)); 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<ll> &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("%lld", *min_element(dp[(1 << k) - 1].begin(), dp[(1 << k) - 1].end())); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 486 ms | 31020 KB | Output is correct |
2 | Correct | 470 ms | 33784 KB | Output is correct |
3 | Correct | 342 ms | 24448 KB | Output is correct |
4 | Correct | 69 ms | 13036 KB | Output is correct |
5 | Correct | 262 ms | 31720 KB | Output is correct |
6 | Correct | 63 ms | 12952 KB | Output is correct |
7 | Correct | 3 ms | 604 KB | Output is correct |
8 | Correct | 2 ms | 700 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 604 KB | Output is correct |
2 | Correct | 4 ms | 604 KB | Output is correct |
3 | Correct | 4 ms | 600 KB | Output is correct |
4 | Correct | 3 ms | 732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1060 ms | 36816 KB | Output is correct |
2 | Correct | 1037 ms | 40112 KB | Output is correct |
3 | Correct | 597 ms | 30228 KB | Output is correct |
4 | Correct | 555 ms | 28172 KB | Output is correct |
5 | Correct | 167 ms | 16996 KB | Output is correct |
6 | Correct | 88 ms | 15328 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2229 ms | 50272 KB | Output is correct |
2 | Correct | 1974 ms | 54912 KB | Output is correct |
3 | Correct | 1930 ms | 53308 KB | Output is correct |
4 | Correct | 1134 ms | 43000 KB | Output is correct |
5 | Correct | 1108 ms | 34564 KB | Output is correct |
6 | Correct | 234 ms | 17984 KB | Output is correct |
7 | Correct | 105 ms | 15200 KB | Output is correct |