結果

問題 No.1449 新プロランド
ユーザー boutarouboutarou
提出日時 2021-03-31 16:05:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 208,948 KB
実行使用メモリ 4,848 KB
最終ジャッジ日時 2023-08-25 16:49:57
合計ジャッジ時間 3,394 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 28 ms
4,624 KB
testcase_06 AC 15 ms
4,380 KB
testcase_07 AC 9 ms
4,376 KB
testcase_08 AC 18 ms
4,820 KB
testcase_09 AC 9 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 4 ms
4,400 KB
testcase_12 AC 17 ms
4,452 KB
testcase_13 AC 10 ms
4,380 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 18 ms
4,416 KB
testcase_16 AC 11 ms
4,380 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 8 ms
4,560 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 27 ms
4,848 KB
testcase_28 AC 15 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n, m; cin >> n >> m;
    vector<ll> a(m), b(m), c(m);
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
    }
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    vector<vector<P>> g(n);
    rep(i, m) {
        g[a[i]].push_back({b[i], c[i]});
        g[b[i]].push_back({a[i], c[i]});
    }
    const ll INF = 1e9;
    vector<ll> dist(n * (ll)2001, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[0 * (ll)2001 + t[0]] = t[0];
    que.push({t[0], t[0]});
    while (!que.empty()) {
        P now = que.top(); que.pop();
        ll nv = now.second, nc = now.first;
        if(nc > dist[nv]) continue;
        for (auto elem : g[nv / (ll)2001]) {
            ll nnv = elem.first * (ll)2001 + min((ll)2000, nv % (ll)2001 + t[elem.first]);
            ll nnc = nc + elem.second / (nv % (ll)2001) + t[elem.first];
            if (nnc < dist[nnv]) {
                dist[nnv] = nnc;
                que.push({nnc, nnv});
            }
        }
    }
    ll ans = INF;
    rep(i, (ll)2001) {
        ans = min(ans, dist[(n - 1) * (ll)2001 + i]);
    }
    cout << ans << endl;
    return 0;
}
0