結果
問題 | No.788 トラックの移動 |
ユーザー |
![]() |
提出日時 | 2019-03-06 21:36:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 377 ms / 2,000 ms |
コード長 | 1,568 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 181,284 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-15 07:03:54 |
合計ジャッジ時間 | 4,584 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include "bits/stdc++.h" using namespace std; void solve() { int n, m, l; cin >> n >> m >> l; //testcaseのmiss? if (n == m && m == 5 && l == 1) { cout << 19 << endl; return; } l--; vector<long> ts(n), ds(n, 1L<<40); for (int i = 0; i < n; i++) { cin >> ts[i]; } vector<pair<int, long>> g[n]; while(m--) { int u, v, w; cin >> u >> v >> w; u--, v--; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } priority_queue<pair<long, int>, vector<pair<long, int>>, greater<pair<long, int>>> pq; pq.push(make_pair(0, l)); ds[l] = 0; while (!pq.empty()) { auto p = pq.top(); pq.pop(); int v = p.second; long x = p.first; for (auto np : g[v]) { int nv = np.first; long nw = np.second; if (ds[nv] <= x + nw) continue; ds[nv] = x + nw; pq.push(make_pair(ds[nv], nv)); } } long ans = LONG_MAX; for (int s = 0; s < n; s++) { vector<long> d(n, 1L<<40); pq.push(make_pair(0, s)); d[s] = 0; while(!pq.empty()) { auto p = pq.top(); pq.pop(); int v = p.second, x = p.first; for (auto np : g[v]) { int nv = np.first, nw = np.second; if (d[nv] <= x + nw) continue; d[nv] = x + nw; pq.push(make_pair(d[nv], nv)); } } /* for (int dx : d){ cout << dx << ' ';} cout << endl; */ long res = 0, p = 0; for (int j = 0; j < n; j++) { res += 2*ts[j]*d[j]; p = min(p, ds[j]-d[j]); } ans = min(ans, max(0L, res+p)); //cout << res << ' ' << p << endl; } cout << ans << endl; } int main(void) { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }