# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
670963 |
2022-12-11T14:20:19 Z |
dozer |
Cities (BOI16_cities) |
C++14 |
|
1887 ms |
72128 KB |
#include <iostream>
#include <climits>
#include <queue>
using namespace std;
typedef long long int Z;
int n, k, m;
vector<int> imp;
vector<vector<pair<int, Z>>> G;
Z d[32][202020];
Z huge = LLONG_MAX / 3;
bool seen[202020];
int main() {
cin.sync_with_stdio(false);
cin >> n >> k >> m;
imp.resize(k);
for(int i = 0; i < k; ++i) {
cin >> imp[i];
--imp[i];
}
G.resize(n);
for(int i = 0; i < m; ++i) {
int a, b;
Z c;
cin >> a >> b >> c;
--a;
--b;
G[a].emplace_back(b, c);
G[b].emplace_back(a, c);
}
fill((Z*)d, (Z*)d + 32 * 202020, huge);
for(int i = 0; i < k; ++i) {
d[1 << i][imp[i]] = 0;
}
priority_queue<pair<Z, int>> Q;
for(int c = 1; c < (1 << k); ++c) {
for(int a = 0; a < c; ++a) {
if((a | c) != c) continue;
int b = c ^ a;
if(b > a) continue;
for(int v = 0; v < n; ++v) {
d[c][v] = min(d[c][v], d[a][v] + d[b][v]);
}
}
fill(seen, seen + n, false);
for(int v = 0; v < n; ++v) {
if(d[c][v] == huge) continue;
Q.emplace(-d[c][v], v);
}
while(!Q.empty()) {
Z cost = -Q.top().first;
int v = Q.top().second;
Q.pop();
if(seen[v]) continue;
seen[v] = true;
for(auto edge : G[v]) {
Z ec = cost + edge.second;
if(ec < d[c][edge.first]) {
d[c][edge.first] = ec;
Q.emplace(-ec, edge.first);
}
}
}
}
Z res = huge;
for(int v = 0; v < n; ++v) {
res = min(res, d[(1 << k) - 1][v]);
}
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
50928 KB |
Output is correct |
2 |
Correct |
20 ms |
50872 KB |
Output is correct |
3 |
Correct |
20 ms |
50896 KB |
Output is correct |
4 |
Correct |
23 ms |
50800 KB |
Output is correct |
5 |
Correct |
24 ms |
50856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
67896 KB |
Output is correct |
2 |
Correct |
438 ms |
67052 KB |
Output is correct |
3 |
Correct |
273 ms |
60780 KB |
Output is correct |
4 |
Correct |
77 ms |
59940 KB |
Output is correct |
5 |
Correct |
243 ms |
67856 KB |
Output is correct |
6 |
Correct |
73 ms |
59892 KB |
Output is correct |
7 |
Correct |
23 ms |
51020 KB |
Output is correct |
8 |
Correct |
24 ms |
51128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
51036 KB |
Output is correct |
2 |
Correct |
24 ms |
51016 KB |
Output is correct |
3 |
Correct |
25 ms |
50948 KB |
Output is correct |
4 |
Correct |
22 ms |
50972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
883 ms |
67964 KB |
Output is correct |
2 |
Correct |
872 ms |
66928 KB |
Output is correct |
3 |
Correct |
539 ms |
60788 KB |
Output is correct |
4 |
Correct |
484 ms |
64876 KB |
Output is correct |
5 |
Correct |
169 ms |
60640 KB |
Output is correct |
6 |
Correct |
108 ms |
62332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1887 ms |
67932 KB |
Output is correct |
2 |
Correct |
1856 ms |
72128 KB |
Output is correct |
3 |
Correct |
1736 ms |
71196 KB |
Output is correct |
4 |
Correct |
1143 ms |
62912 KB |
Output is correct |
5 |
Correct |
936 ms |
68996 KB |
Output is correct |
6 |
Correct |
234 ms |
64684 KB |
Output is correct |
7 |
Correct |
101 ms |
65672 KB |
Output is correct |