結果

問題 No.788 トラックの移動
ユーザー Shuz*Shuz*
提出日時 2019-02-08 22:16:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,237 bytes
コンパイル時間 1,884 ms
コンパイル使用メモリ 185,328 KB
実行使用メモリ 34,728 KB
最終ジャッジ日時 2023-09-14 03:45:16
合計ジャッジ時間 5,190 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#define input(a) scanf("%lld", &(a))
//#define output(a) printf("%lld\n", (a))

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

def input() {
    ll A;
    cin >> A;
    return A;
}

template <typename T> struct DJK {
    ll V;
    using P = pair<ll, ll>;
    vector<vector<P>> G;
    vector<T> dist;
    vector<bool> used;
    DJK(ll v) : V(v), G(v), dist(v), used(v) {
        fill_n(dist.begin(), V, INF);
        fill_n(used.begin(), V, false);
    }
    void setDist(ll a, ll b, ll d) { G[a].push_back(P(d, b)); }
    void culc(ll s = 0) {
        priority_queue<P, vector<P>, greater<P>> Q;
        fill_n(dist.begin(), V, INF);
        fill_n(used.begin(), V, false);
        Q.push(P(0, s));
        while (!Q.empty()) {
            T d;
            ll t;
            tie(d, t) = Q.top(), Q.pop();
            if (used[t]) continue;
            used[t] = true, dist[t] = d;
            for (P e : G[t]) {
                if (dist[e.second] <= d + e.first) continue;
                Q.push(P(d + e.first, e.second));
            }
        }
    }
};

ll A, B, C, N, M, L, res = INF;
vector<ll> T;
vector<vector<ll>> D;

signed main() {
    cin >> N >> M >> L;
    DJK<ll> dijk(N);
    rep(i, N) T.push_back(input());
    ll cnt = 0;
    rep(i, N) if (T[i]) cnt++;
    if (cnt == 0) return puts("0") & 0;
    rep(i, M) {
        cin >> A >> B >> C;
        dijk.setDist(A - 1, B - 1, C);
        dijk.setDist(B - 1, A - 1, C);
    }

    rep(i, N) dijk.culc(i), D.push_back(dijk.dist);

    rep(i, N) {
        ll S = 0, P = D[L - 1][i];
        rep(j, N) {
            S += 2 * D[i][j] * T[j];
            if (T[j]) P = min(P, D[L - 1][j] - D[i][j]);
        }
        res = min(res, S + P);
    }

    cout << res << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17
0