# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1093105 |
2024-09-26T00:47:07 Z |
juicy |
Cities (BOI16_cities) |
C++17 |
|
1368 ms |
41324 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
const long long inf = 1e18;
int n, k, m; cin >> n >> k >> m;
vector<int> city(k);
for (int &u : city) {
cin >> u; --u;
}
vector<vector<array<int, 2>>> g(n);
while (m--) {
int u, v, c; cin >> u >> v >> c; --u, --v;
g[u].push_back({v, c});
g[v].push_back({u, c});
}
auto dijkstra = [&](vector<long long> &d) {
using T = pair<long long, int>;
priority_queue<T, vector<T>, greater<T>> pq;
for (int i = 0; i < n; ++i) {
pq.push({d[i], i});
}
while (pq.size()) {
auto [c, u] = pq.top(); pq.pop();
if (c != d[u]) {
continue;
}
for (auto [v, w] : g[u]) {
if (d[v] > c + w) {
pq.push({d[v] = c + w, v});
}
}
}
return d;
};
vector d(1 << k, vector<long long>(n, inf));
for (int i = 0; i < k; ++i) {
d[1 << i][city[i]] = 0;
}
for (int m = 1; m < 1 << k; ++m) {
for (int i = 0; i < k; ++i) {
if (m >> i & 1) {
for (int j = 0; j < n; ++j) {
d[m][j] = min(d[m][j], d[m - (1 << i)][j] + d[1 << i][j]);
}
}
}
dijkstra(d[m]);
}
long long res = inf;
for (int i = 0; i < n; ++i) {
res = min(res, d.back()[i]);
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
21804 KB |
Output is correct |
2 |
Correct |
343 ms |
22532 KB |
Output is correct |
3 |
Correct |
198 ms |
15828 KB |
Output is correct |
4 |
Correct |
37 ms |
5204 KB |
Output is correct |
5 |
Correct |
171 ms |
20340 KB |
Output is correct |
6 |
Correct |
37 ms |
5108 KB |
Output is correct |
7 |
Correct |
3 ms |
600 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
600 KB |
Output is correct |
2 |
Correct |
4 ms |
732 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
704 ms |
28416 KB |
Output is correct |
2 |
Correct |
673 ms |
28220 KB |
Output is correct |
3 |
Correct |
423 ms |
22112 KB |
Output is correct |
4 |
Correct |
365 ms |
17868 KB |
Output is correct |
5 |
Correct |
103 ms |
8308 KB |
Output is correct |
6 |
Correct |
41 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1348 ms |
41324 KB |
Output is correct |
2 |
Correct |
1368 ms |
40652 KB |
Output is correct |
3 |
Correct |
1312 ms |
40636 KB |
Output is correct |
4 |
Correct |
877 ms |
34692 KB |
Output is correct |
5 |
Correct |
773 ms |
23604 KB |
Output is correct |
6 |
Correct |
164 ms |
9536 KB |
Output is correct |
7 |
Correct |
49 ms |
6928 KB |
Output is correct |