結果

問題 No.788 トラックの移動
ユーザー roarisroaris
提出日時 2020-12-03 10:29:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,599 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 209,748 KB
実行使用メモリ 34,776 KB
最終ジャッジ日時 2023-10-11 19:21:01
合計ジャッジ時間 5,935 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 491 ms
34,500 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 109 ms
11,020 KB
testcase_05 AC 480 ms
34,776 KB
testcase_06 AC 493 ms
34,548 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 WA -
testcase_16 AC 519 ms
34,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;

int N, M, L;
int t[2010];
vector<P> G[2010];
vector<vector<int>> D;

vector<int> dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> q;
    vector<int> d(N);
    rep(i, N) d[i] = 1000000000000;
    d[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top(); q.pop();
        int v = p.second;
        if (d[v]<p.first) continue;
        rep(i, G[v].size()) {
            int nv = G[v][i].first, w = G[v][i].second;
            if (d[nv]>d[v]+w) {
                d[nv] = d[v]+w;
                q.push(P(d[nv], nv));
            }
        }
    }
    return d;
}

signed main() {
    //ループ変数が被っていないか?
    //制約を確認しているか?
    //変数のtypoがないか?
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M >> L;
    int s = 0;
    rep(i, N) {
        cin >> t[i];
        s += t[i];
    }
    rep(i, N) {
        if (t[i]==s) {
            cout << 0 << endl;
            exit(0);
        }
    }
    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        G[a-1].pb(P(b-1, c));
        G[b-1].pb(P(a-1, c));
    }
    rep(i, N) D.pb(dijkstra(i));
    
    int ans = 1000000000000000;
    rep(i, N) {
        int base = 0;
        rep(j, N) base += 2*t[j]*D[i][j];
        rep(j, N) {
            int cand = base+D[L-1][j]+D[j][i];
            if (t[j]>=1) cand -= 2*D[i][j];
            ans = min(ans, cand);
        }
    }
    cout << ans << endl;
}
0