Submission #945878

#TimeUsernameProblemLanguageResultExecution timeMemory
945878phoenix0423Cities (BOI16_cities)C++17
52 / 100
6091 ms239832 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #pragma GCC optimize("Ofast") #define pb push_back #define eb emplace_back #define f first #define s second #define int long long #define lowbit(x) x&-x const int maxn = 1e5 + 5; const int INF = 1e18; int dp[maxn][32]; vector<pll> adj[maxn]; struct info{ int d, pos, st; info(){} info(int _d, int _pos, int _st) : d(_d), pos(_pos), st(_st){} bool operator < (const info& other) const{ return d < other.d; } bool operator > (const info& other) const{ return d > other.d; } }; signed main(void){ int n, k, m; cin>>n>>k>>m; vector<int> a(k); for(int i = 0; i < k; i++) cin>>a[i], a[i] --; for(int i = 0; i < m; i++){ int a, b, w; cin>>a>>b>>w; a--, b--; adj[a].eb(b, w); adj[b].eb(a, w); } for(int i = 0; i < n; i++){ for(int j = 1; j < (1 << j); j++) dp[i][j] = INF; } priority_queue<info, vector<info>, greater<info>> q; for(int i = 0; i < k; i++){ dp[a[i]][(1 << i)] = 0; q.push(info(0, a[i], (1 << i))); } while(!q.empty()){ auto [d, pos, st] = q.top(); q.pop(); if(dp[pos][st] != d) continue; for(auto [x, w] : adj[pos]){ for(int i = 0; i < (1 << k); i++){ if(dp[x][i | st] > dp[x][i] + d + w){ dp[x][i | st] = dp[x][i] + d + w; q.push(info(dp[x][i | st], x, i | st)); } } } } int ans = INF; for(int i = 0; i < n; i++) ans = min(ans, dp[i][(1 << k) - 1]); cout<<ans<<"\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...