Submission #745772

#TimeUsernameProblemLanguageResultExecution timeMemory
745772vjudge1Cities (BOI16_cities)C++17
14 / 100
261 ms18320 KiB
#include <bits/stdc++.h> // #define MULTI_TEST_CASE // #define TEST_TEXT using namespace std; #define ll long long #define MAX(a, b) (a) = max((a), (b)) #define MIN(a, b) (a) = min((a), (b)) #define all(a) (a).begin(), (a).end() #define sortedpair(a, b) {min((a), (b)), max((a), (b))} const ll MOD = 1e9+7; struct edge { int to, w; }; int n, k, m; vector<vector<edge>> v; vector<int> w; vector<ll> dijkstra(int start){ vector<ll> d1(n, 1e18); d1[start] = 0; priority_queue<pair<ll, int>> q; q.push({0, start}); while(!q.empty()){ ll d = -q.top().first; int c = q.top().second; q.pop(); if(d > d1[c])continue; for(auto&i : v[c]){ if(d + i.w < d1[i.to]){ d1[i.to] = d + i.w; q.push({-d1[i.to], i.to}); } } } return d1; } void solve(){ cin>>n>>k>>m; w.assign(k, 0); for(int&i:w){cin>>i; i--;} v.assign(n, {}); for(int i = 0; i < m; i++){ int a, b, c; cin>>a>>b>>c; a--; b--; v[a].push_back({b, c}); v[b].push_back({a, c}); } vector<ll> d1 = dijkstra(w[0]); vector<ll> d2 = dijkstra(w[1]); vector<ll> d3; if(k == 2){ d3.assign(n, 0); } else { d3 = dijkstra(w[2]); } ll ans = 1e18; for(int i = 0; i < n; i++){ MIN(ans, d1[i] + d2[i] + d3[i]); } cout<<ans<<endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int _t = 1; #ifdef MULTI_TEST_CASE cin >> _t; #endif for(int _i = 0; _i < _t; _i++){ #ifdef TEST_TEXT cout<<"Case #"<<_i+1<<": "; #endif solve(); } return 0; }
#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...