# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1111224 |
2024-11-11T19:15:31 Z |
f0rizen |
Cities (BOI16_cities) |
C++17 |
|
6000 ms |
170644 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll infll = 1e18;
template<typename T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
int32_t main() {
#ifdef LOCAL
freopen("/tmp/input.txt", "r", stdin);
#else
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int n, k, m;
cin >> n >> k >> m;
vector<int> a(k);
cin >> a;
for (auto &i : a) {
--i;
}
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; ++i) {
int u, v, w;
cin >> u >> v >> w;
--u, --v;
g[u].push_back({v, w});
g[v].push_back({u, w});
}
vector<vector<ll>> dp(1 << k, vector<ll>(n, infll));
using pii = pair<ll, pair<int, int>>;
priority_queue<pii, vector<pii>, greater<pii>> pq;
for (int i = 0; i < k; ++i) {
dp[1 << i][a[i]] = 0;
pq.push({dp[1 << i][a[i]], {1 << i, a[i]}});
}
while (!pq.empty()) {
auto [_, a] = pq.top();
pq.pop();
auto [mask, v] = a;
if (_ > dp[mask][v]) {
continue;
}
for (auto [u, w] : g[v]) {
if (dp[mask][u] > dp[mask][v] + w) {
dp[mask][u] = dp[mask][v] + w;
pq.push({dp[mask][u], {mask, u}});
}
int mm = ((1 << k) - 1) ^ mask;
for (int s = mm; s > 0; s = (s - 1) & mm) {
if (dp[mask | s][u] > dp[mask][v] + dp[s][u] + w) {
dp[mask | s][u] = dp[mask][v] + dp[s][u] + w;
pq.push({dp[mask | s][u], {mask | s, u}});
}
}
}
}
ll ans = infll;
for (int i = 0; i < n; ++i) {
ans = min(ans, dp[(1 << k) - 1][i]);
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
528 ms |
36752 KB |
Output is correct |
2 |
Correct |
474 ms |
32128 KB |
Output is correct |
3 |
Correct |
243 ms |
19356 KB |
Output is correct |
4 |
Correct |
61 ms |
9152 KB |
Output is correct |
5 |
Correct |
186 ms |
20792 KB |
Output is correct |
6 |
Correct |
45 ms |
8512 KB |
Output is correct |
7 |
Correct |
4 ms |
848 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1228 KB |
Output is correct |
2 |
Correct |
8 ms |
1228 KB |
Output is correct |
3 |
Correct |
5 ms |
848 KB |
Output is correct |
4 |
Correct |
5 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2205 ms |
90764 KB |
Output is correct |
2 |
Correct |
2201 ms |
91892 KB |
Output is correct |
3 |
Correct |
1240 ms |
38024 KB |
Output is correct |
4 |
Correct |
1186 ms |
51076 KB |
Output is correct |
5 |
Correct |
295 ms |
26852 KB |
Output is correct |
6 |
Correct |
104 ms |
12220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6070 ms |
170644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |