제출 #745823

#제출 시각아이디문제언어결과실행 시간메모리
745823vjudge1Cities (BOI16_cities)C++17
15 / 100
229 ms8384 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define fi first #define se second struct edge { int from, to, wei; bool operator < (const edge &other) const { return wei > other.wei; } }; const int maxn = 1000; const int inf = 1e16 + 42; int n, k, m; vector<edge> graph[1 + maxn]; bool special[1 + maxn]; vector<int> specials; void dijkstra(int source, vector<int> &dist) { dist.assign(1 + n, -1); // dist[source] = 0; priority_queue<edge> q; q.push({0, source, 0}); while(!q.empty()) { edge cur = q.top(); q.pop(); if(dist[cur.to] != -1) { continue; } dist[cur.to] = cur.wei; for(const edge &nei : graph[cur.to]) { if(dist[nei.to] == -1 || dist[nei.to] /*<*/> dist[cur.to] + nei.wei) { q.push({cur.to, nei.to, dist[cur.to] + nei.wei}); } } } } vector<pii > prs = {{0, 1}, {0, 2}, {0, 3}}; vector<pii > opp_prs = {{2, 3}, {1, 3}, {1, 2}}; void solve() { cin >> n >> k >> m; for(int i = 0; i < k; i++) { int x; cin >> x; special[x] = true; specials.pb(x); } for(int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; graph[a].pb({a, b, c}); graph[b].pb({b, a, c}); } int ans = inf; vector<vector<int> > distances(1 + n); for(int i = 1; i <= n; i++) { dijkstra(i, distances[i]); } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { for(int idx = 0; idx < 3; idx++) { int a = specials[prs[idx].fi], b = specials[prs[idx].se]; int c = specials[opp_prs[idx].fi], d = specials[opp_prs[idx].se]; int cur = 0; cur += distances[i][j]; cur += distances[i][a]; cur += distances[i][b]; cur += distances[j][c]; cur += distances[j][d]; if(ans > cur) { ans = cur; } } } } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); 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...