結果

問題 No.788 トラックの移動
ユーザー kappybarkappybar
提出日時 2020-05-08 16:28:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 960 ms / 2,000 ms
コード長 1,768 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 178,940 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-21 17:35:33
合計ジャッジ時間 7,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 878 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 199 ms
4,380 KB
testcase_05 AC 855 ms
4,380 KB
testcase_06 AC 874 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,500 KB
testcase_15 AC 206 ms
4,380 KB
testcase_16 AC 960 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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]);
            }
        }
        if(res != 0) res += mn;
        ans = min(ans,res);
    }
    cout << ans << endl;
    return 0;
}
0