結果
| 問題 |
No.788 トラックの移動
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-08 16:16:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,755 bytes |
| コンパイル時間 | 1,646 ms |
| コンパイル使用メモリ | 180,628 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-03 09:52:04 |
| 合計ジャッジ時間 | 7,008 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 2 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n = 2005,m,l;
vector<vector<pair<ll,ll>>> graph(n,vector<pair<ll,ll>>());
vector<ll> dijkstra(ll start){
vector<ll> shortest(n);
vector<bool> visited(n,false);
priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
pq.push(make_pair(0,start));
while (!pq.empty()){
pair<ll,ll> now = pq.top();
pq.pop();
ll cost,node;
tie(cost,node) = now;
if(visited[node]){
continue;
}else{
shortest[node] = cost;
visited[node] = true;
for(pair<ll,ll> next:graph[node]){
ll next_cost,next_node;
tie(next_cost,next_node) = next;
pq.push(make_pair(cost+next_cost,next_node));
}
}
}
return shortest;
}
int main(){
cin >> n >>m >> l;
--l;
vector<ll> t(n);
rep(i,n) cin >> t[i];
rep(i,m){
ll a,b,c;
cin >>a >> b >> c;
--a;--b;
graph[a].push_back(pll(c,b));
graph[b].push_back(pll(c,a));
}
vector<ll> disL = dijkstra(l);
ll ans = LINF;
rep(target,n){
vector<ll> dist = dijkstra(target);
ll res = 0;
rep(i,n){
res += 2 * dist[i] * t[i];
}
ll mn = dist[l];
rep(i,n){
if(t[i] > 0){
mn = min(mn,disL[i]-dist[i]);
}
}
res += mn;
ans = min(ans,res);
}
cout << ans << endl;
return 0;
}