Submission #1073218

#TimeUsernameProblemLanguageResultExecution timeMemory
1073218Jarif_RahmanCities (BOI16_cities)C++17
100 / 100
1381 ms48424 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll inf = 1e18; const int N = 1e5; bitset<N> bl; void dijkstra(int n, vector<pair<int, ll>> *graph, ll* dis){ bl.reset(); priority_queue<pair<ll, int>> pq; for(int s = 0; s < n; s++) if(dis[s] < inf) pq.push({-dis[s], s}); while(!pq.empty()){ int nd = pq.top().second; pq.pop(); if(bl[nd]) continue; bl[nd] = 1; for(auto [x, w]: graph[nd]) if(dis[nd]+w < dis[x]){ dis[x] = dis[nd]+w; pq.push({-dis[x], x}); } } } int n, m, k; vector<pair<int, ll>> graph[N]; vector<int> ic; ll dis[32][N]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> m; ic.resize(k); for(int &x: ic) cin >> x, x--; for(int i = 0; i < m; i++){ int a, b; ll w; cin >> a >> b >> w; a--, b--; graph[a].push_back({b, w}); graph[b].push_back({a, w}); } for(int i = 0; i < k; i++){ fill(dis[1<<i], dis[1<<i]+n, inf); dis[1<<i][ic[i]] = 0; dijkstra(n, graph, dis[1<<i]); } for(int mask = 1; mask < (1<<k); mask++){ if(__builtin_popcount(mask) < 2) continue; fill(dis[mask], dis[mask]+n, inf); for(int submask = (mask-1)&mask; submask > 0; submask = (submask-1)&mask){ for(int i = 0; i < n; i++) dis[mask][i] = min(dis[mask][i], dis[submask][i]+dis[mask^submask][i]); } dijkstra(n, graph, dis[mask]); } cout << *min_element(dis[(1<<k)-1], dis[(1<<k)-1]+n) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...