結果

問題 No.788 トラックの移動
ユーザー face4face4
提出日時 2019-02-11 09:49:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,575 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 83,788 KB
実行使用メモリ 19,412 KB
最終ジャッジ日時 2023-09-25 00:24:17
合計ジャッジ時間 4,146 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<queue>
#include<vector>
#include<climits>
using namespace std;

const int INF = INT_MAX;
typedef long long ll;

int main(){
    int n, m, l;
    cin >> n >> m >> l;
    l--;

    vector<int> t(n);
    for(int i = 0; i < n; i++)  cin >> t[i];
    int cnt = 0;
    for(int i = 0; i < n; i++)  if(t[i])    cnt++;
    if(cnt == 1){
        cout << 0 << endl;
        return 0;
    }

    vector<vector<int>> v(n, vector<int>(n, INF));
    vector<pair<int,int>> path[n];
    int a, b, c;
    while(m-- > 0){
        cin >> a >> b >> c;
        a--, b--;
        path[a].push_back({c,b});
        path[b].push_back({c,a});
    }

    for(int i = 0; i < n; i++){
        priority_queue<pair<int,int>> pq;
        pq.push({-0, i});
        while(!pq.empty()){
            pair<int,int> now = pq.top();   pq.pop();
            int cost = -now.first, pos = now.second;
            if(cost >= v[i][pos])   continue;
            v[i][pos] = cost;
            for(pair<int,int> p : path[pos]){
                if(cost+p.first < v[i][p.second]){
                    pq.push({-(cost+p.first), p.second});
                }
            }
        }
    }
    
    vector<ll> gather(n, 0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            gather[i] += 2 * v[i][j] * t[j];
        }
    }
    
    ll ans = 1ll<<60;
    for(int s = 0; s < n; s++){
        if(t[s] == 0)   continue;
        for(int g = 0; g < n; g++){
            ans = min(ans, gather[g] + v[l][s] - v[s][g]);
        }
    }

    cout << ans << endl;

    return 0;
}
0