# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1118367 | VinhLuu | Cities (BOI16_cities) | C++17 | 2847 ms | 96640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()
using namespace std;
typedef pair<ll, ll> pii;
const int N = 1e6 + 5;
const int M = 1e6 + 5;
const ll oo = 1e16;
int n, k, m;
ll f[N][(1 << 6)];
int a[N], rev[N];
vector<pii> p[N];
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define task "v"
if(fopen(task ".inp","r")){
freopen(task ".inp","r",stdin);
freopen(task ".out","w",stdout);
}
cin >> n >> k >> m;
for(int i = 1; i <= k; i ++){
cin >> a[i]; rev[a[i]] = i;
}
for(int i = 1; i <= m; i ++) {
int x, y, c; cin >> x >> y >> c;
p[x].push_back({y, c});
p[y].push_back({x, c});
}
for(int msk = 0; msk < (1 << k); msk ++) for(int i = 1; i <= n; ++ i) f[i][msk] = oo;
for(int i = 1; i <= k; i ++) f[a[i]][(1 << (i - 1))] = 0;
for(int msk = 1; msk < (1 << k); msk ++){
priority_queue<pii, vector<pii>, greater<pii>> pq;
for(int i = 1; i <= n; i ++){
for(int sub = msk; sub > 0; sub = (sub - 1) & msk){
f[i][msk] = min(f[i][msk], f[i][sub] + f[i][(msk ^ sub)]);
}
pq.push({f[i][msk], i});
}
while(!pq.empty()){
ll w, u; tie(w, u) = pq.top(); pq.pop();
if(w > f[u][msk]) continue;
for(auto [j, val] : p[u]) if(f[j][msk] > w + val){
pq.push({f[j][msk] = w + val, j});
}
}
}
ll ans = oo;
for(int i = 1; i <= n; i ++) ans = min(ans, f[i][(1 << k) - 1]);
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |