Submission #640881

#TimeUsernameProblemLanguageResultExecution timeMemory
640881devariaotaCities (BOI16_cities)C++17
14 / 100
327 ms19936 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; const ll mod=1e9+7; const ll maxn=1e5+5; const ll INF=1e18; #define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fi first #define se second #define pb push_back #define ub upper_bound #define lb lower_bound #define endl '\n' int n, k, m, arr[5], u, v, w; ll dis[maxn][5], ans=INF; vector<pii> adj[maxn]; int main() { ok cin >> n >> k >> m; for(int i=0; i<k; i++) cin >> arr[i]; for(int i=0; i<m; i++) { cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } for(int i=0; i<k; i++) { for(int j=1; j<=n; j++) dis[j][i]=INF; dis[arr[i]][i]=0; priority_queue<pll, vector<pll>, greater<pll>> pq; pq.push({0, arr[i]}); while(!pq.empty()) { pll fr=pq.top(); pq.pop(); if(fr.fi>dis[fr.se][i]) continue; for(auto it : adj[fr.se]) { if(dis[it.fi][i]>dis[fr.se][i]+it.se) { dis[it.fi][i]=dis[fr.se][i]+it.se; pq.push({dis[it.fi][i], it.fi}); } } } } for(int i=1; i<=n; i++) { ll cur=0; for(int j=0; j<k; j++) cur+=dis[i][j]; ans=min(ans, cur); } cout << ans; }
#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...