結果
問題 | No.788 トラックの移動 |
ユーザー |
![]() |
提出日時 | 2024-02-09 17:57:05 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,378 bytes |
コンパイル時間 | 2,171 ms |
コンパイル使用メモリ | 214,756 KB |
実行使用メモリ | 34,688 KB |
最終ジャッジ日時 | 2024-09-28 13:03:57 |
合計ジャッジ時間 | 5,428 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll n, m, x, y, z, l; cin >> n >> m >> l; l--; vector<ll> t(n); for (ll i = 0; i < n; i++) { cin >> t[i]; } vector<vector<pair<ll, ll>>> e(n); for (int i=0; i<m; i++){ cin >> x >> y >> z; x--; y--; e[x].push_back({y, z}); e[y].push_back({x, z}); } vector dist(n, vector<ll>(n, 1e18)); for (int i=0; i<n; i++){ priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que; que.push({0, i}); dist[i][i] = 0; while(!que.empty()){ tie(z, x) = que.top(); que.pop(); if (dist[i][x] < z) continue; for (auto [y, w] : e[x]){ if (dist[i][y] > dist[i][x] + w){ dist[i][y] = dist[i][x] + w; que.push({dist[i][y], y}); } } } } ll ans = 1e18; for (int i=0; i<n; i++){ ll sm = 0; for (int j=0; j<n; j++){ sm += t[j] * dist[i][j] * 2; } ans = min(ans, sm+dist[i][l]); for (int j=0; j<n; j++){ if (t[j] > 0) ans = min(ans, sm+dist[l][j]-dist[i][j]); } } cout << ans << endl; return 0; }