# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
377142 |
2021-03-13T03:45:06 Z |
pavement |
Cities (BOI16_cities) |
C++17 |
|
2379 ms |
68036 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() {
ios::sync_with_stdio(0);
cin.tie(0);
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 = c; a; a = (a - 1) & c) {
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 = d[(1 << k) - 1][imp[0]];
cout << res << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
50924 KB |
Output is correct |
2 |
Correct |
28 ms |
50944 KB |
Output is correct |
3 |
Correct |
27 ms |
50944 KB |
Output is correct |
4 |
Correct |
29 ms |
50924 KB |
Output is correct |
5 |
Correct |
28 ms |
50924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
635 ms |
67936 KB |
Output is correct |
2 |
Correct |
616 ms |
67028 KB |
Output is correct |
3 |
Correct |
380 ms |
60776 KB |
Output is correct |
4 |
Correct |
103 ms |
60012 KB |
Output is correct |
5 |
Correct |
358 ms |
67936 KB |
Output is correct |
6 |
Correct |
97 ms |
60012 KB |
Output is correct |
7 |
Correct |
30 ms |
51180 KB |
Output is correct |
8 |
Correct |
29 ms |
51180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
51180 KB |
Output is correct |
2 |
Correct |
34 ms |
51200 KB |
Output is correct |
3 |
Correct |
31 ms |
51068 KB |
Output is correct |
4 |
Correct |
31 ms |
51052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1220 ms |
67980 KB |
Output is correct |
2 |
Correct |
1192 ms |
67116 KB |
Output is correct |
3 |
Correct |
794 ms |
60768 KB |
Output is correct |
4 |
Correct |
666 ms |
65076 KB |
Output is correct |
5 |
Correct |
210 ms |
60880 KB |
Output is correct |
6 |
Correct |
110 ms |
62444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2379 ms |
68036 KB |
Output is correct |
2 |
Correct |
2373 ms |
67952 KB |
Output is correct |
3 |
Correct |
2342 ms |
67028 KB |
Output is correct |
4 |
Correct |
1645 ms |
60768 KB |
Output is correct |
5 |
Correct |
1250 ms |
64864 KB |
Output is correct |
6 |
Correct |
306 ms |
60880 KB |
Output is correct |
7 |
Correct |
125 ms |
62188 KB |
Output is correct |