# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1121259 |
2024-11-28T16:08:52 Z |
LonlyR |
Cities (BOI16_cities) |
C++17 |
|
6000 ms |
168524 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<ll,int,int> tpl;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 1e5 + 5;
vector<pii> adj[mn];
ll dist[mn][1 << 5], gather[mn];
bool vis[mn][1 << 5];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, k, m; cin >> n >> k >> m;
for (int i = 1; i <= n; i++)
for (int mask = 1; mask < (1 << k); mask++) dist[i][mask] = LLONG_MAX;
priority_queue<tpl> pq;
vector<int> fav(k);
for (int i = 0; i < k; i++) {
cin >> fav[i];
dist[fav[i]][1 << i] = 0;
pq.emplace(0, fav[i], 1 << i);
}
while (m--) {
int a, b, c; cin >> a >> b >> c;
adj[a].emplace_back(b, c);
adj[b].emplace_back(a, c);
}
while (pq.size()) {
ll d; int u, mask; tie(d, u, mask) = pq.top(); pq.pop();
if (vis[u][mask]) continue;
vis[u][mask] = 1;
for (pii it : adj[u]) {
int v, w; tie(v, w) = it;
for (int supr = mask; supr < (1 << k); supr = (supr + 1) | mask) {
if (dist[v][supr ^ mask] == LLONG_MAX) continue;
if (dist[u][mask] + dist[v][supr ^ mask] + w < dist[v][supr]) {
dist[v][supr] = dist[u][mask] + dist[v][supr ^ mask] + w;
pq.emplace(-dist[v][supr], v, supr);
}
}
}
}
ll ans = LLONG_MAX;
for (int i : fav)
ans = min(ans, dist[i][(1 << k) - 1]);
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2584 KB |
Output is correct |
3 |
Correct |
3 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
3 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
824 ms |
53760 KB |
Output is correct |
2 |
Correct |
790 ms |
53236 KB |
Output is correct |
3 |
Correct |
362 ms |
38328 KB |
Output is correct |
4 |
Correct |
77 ms |
8648 KB |
Output is correct |
5 |
Correct |
305 ms |
41272 KB |
Output is correct |
6 |
Correct |
45 ms |
8140 KB |
Output is correct |
7 |
Correct |
5 ms |
3408 KB |
Output is correct |
8 |
Correct |
4 ms |
3152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3788 KB |
Output is correct |
2 |
Correct |
12 ms |
3772 KB |
Output is correct |
3 |
Correct |
7 ms |
3152 KB |
Output is correct |
4 |
Correct |
8 ms |
3532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2664 ms |
102916 KB |
Output is correct |
2 |
Correct |
2152 ms |
102484 KB |
Output is correct |
3 |
Correct |
1006 ms |
50588 KB |
Output is correct |
4 |
Correct |
1589 ms |
55516 KB |
Output is correct |
5 |
Correct |
335 ms |
26828 KB |
Output is correct |
6 |
Correct |
133 ms |
11196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6044 ms |
168524 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |