結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2024-02-09 18:02:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 493 ms / 2,000 ms |
| コード長 | 1,528 bytes |
| コンパイル時間 | 2,300 ms |
| コンパイル使用メモリ | 207,428 KB |
| 最終ジャッジ日時 | 2025-02-19 03:02:43 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#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});
}
}
}
}
int cnt=0;
for (int i=0; i<n; i++){
if (t[i] > 0) cnt++;
}
if (cnt == 1){
cout << 0 << endl;
return 0;
}
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;
}
srjywrdnprkt