結果

問題 No.788 トラックの移動
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-02-09 09:33:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,748 bytes
コンパイル時間 2,859 ms
コンパイル使用メモリ 175,696 KB
実行使用メモリ 34,744 KB
最終ジャッジ日時 2023-09-14 11:04:10
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/








int N, M, L, T[2010];
vector<pair<int, int>> E[2010];
vector<ll> D[2010];
//---------------------------------------------------------------------------------------------------
int vis[101010];
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
void dijk(int s, vector<ll> &D) {
    D.resize(N);
    rep(i, 0, N) D[i] = infl;
    rep(i, 0, N) vis[i] = 0;

    min_priority_queue<pair<ll, int>> que;

    D[s] = 0;
    que.push({ 0, s });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        ll cst = q.first;
        int cu = q.second;

        if (vis[cu]) continue;
        vis[cu] = 1;

        fore(p, E[cu]) {
            ll cst2 = cst + p.second;
            int to = p.first;

            if (chmin(D[to], cst2)) que.push({ D[to], to });
        }
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> L; L--;
    rep(i, 0, N) cin >> T[i];
    rep(i, 0, M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        E[a].push_back({ b,c });
        E[b].push_back({ a,c });
    }

    rep(i, 0, N) dijk(i, D[i]);

    ll ans = infl;
    rep(p, 0, N) {
        ll base = 0;
        rep(i, 0, N) base += T[i] * D[p][i] * 2;
        rep(st, 0, N) if(T[st]) {
            ll sm = D[L][st] + D[st][p];
            ll cand = base - D[p][st] * 2 + sm;
            chmin(ans, cand);
        }
    }

    if (ans == infl) ans = 0;
    cout << ans << endl;
}
0