結果
問題 | No.788 トラックの移動 |
ユーザー |
![]() |
提出日時 | 2019-02-08 22:53:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,325 bytes |
コンパイル時間 | 2,183 ms |
コンパイル使用メモリ | 204,764 KB |
最終ジャッジ日時 | 2025-01-06 21:02:19 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 2 |
ソースコード
#include <bits/stdc++.h> #define int long long using namespace std; typedef pair<int, int> P; const int INF = 1e18; int n, m, l; int t[2000]; vector<P> G[2000]; int d[2000][2000]; struct Dijkstra{ vector<int> d; Dijkstra(int V){ d.resize(V, INF); } void calc(int s){ d[s] = 0; priority_queue<P, vector<P>, greater<P> > q; q.push(P(d[s], s)); while(!q.empty()){ P p = q.top(); q.pop(); int from = p.second; int cost = p.first; if(d[from] < cost) continue; for(auto e : G[from]){ int next = e.first; int newCost = cost + e.second; if(d[next] > newCost){ d[next] = newCost; q.push(P(newCost, next)); } } } } }; signed main(){ cin >> n >> m >> l; l--; for(int i = 0; i < n; i++) cin >> t[i]; for(int i = 0; i < m; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back({b, c}); G[b].push_back({a, c}); } for(int i = 0; i < n; i++){ Dijkstra dk(n); dk.calc(i); for(int j = 0; j < n; j++){ d[i][j] = dk.d[j]; } } int ans = INF; for(int i = 0; i < n; i++){ int tmp = d[l][i]; for(int j = 0; j < n; j++){ tmp += t[j] * d[i][j] * 2; } int MAX = 0; for(int j = 0; j < n; j++){ if(t[j] == 0) continue; MAX = max(MAX, d[l][i] + d[i][j] - d[l][j]); } tmp -= MAX; ans = min(ans, tmp); } cout << ans << endl; }