結果

問題 No.2805 Go to School
ユーザー Today03Today03
提出日時 2024-07-12 21:45:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 1,544 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 215,052 KB
実行使用メモリ 22,124 KB
最終ジャッジ日時 2024-07-16 01:38:59
合計ジャッジ時間 8,430 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 171 ms
16,896 KB
testcase_05 AC 213 ms
14,332 KB
testcase_06 AC 110 ms
9,620 KB
testcase_07 AC 105 ms
9,344 KB
testcase_08 AC 187 ms
14,464 KB
testcase_09 AC 107 ms
9,216 KB
testcase_10 AC 109 ms
9,184 KB
testcase_11 AC 302 ms
20,544 KB
testcase_12 AC 187 ms
14,280 KB
testcase_13 AC 272 ms
17,912 KB
testcase_14 AC 39 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 160 ms
11,752 KB
testcase_19 AC 97 ms
8,704 KB
testcase_20 AC 235 ms
16,244 KB
testcase_21 AC 297 ms
20,468 KB
testcase_22 AC 134 ms
11,008 KB
testcase_23 AC 208 ms
14,960 KB
testcase_24 AC 214 ms
15,068 KB
testcase_25 AC 65 ms
8,508 KB
testcase_26 AC 236 ms
22,124 KB
testcase_27 AC 158 ms
16,072 KB
testcase_28 AC 13 ms
6,940 KB
testcase_29 AC 23 ms
7,552 KB
testcase_30 AC 84 ms
12,008 KB
testcase_31 AC 127 ms
10,368 KB
testcase_32 AC 236 ms
21,036 KB
testcase_33 AC 256 ms
19,096 KB
testcase_34 AC 2 ms
6,940 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 100 ms
9,216 KB
testcase_37 AC 109 ms
10,240 KB
testcase_38 AC 191 ms
15,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N, M, L;
    ll S, E;
    cin >> N >> M >> L >> S >> E;

    vector<vector<pair<int, ll>>> G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        ll t;
        cin >> a >> b >> t;
        a--;
        b--;
        G[a].push_back({b, t});
        G[b].push_back({a, t});
    }

    vector<bool> T(N, false);
    for (int i = 0; i < L; i++) {
        int t;
        cin >> t;
        t--;
        T[t] = true;
    }

    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
    pq.push({0, 0});

    vector<ll> D(2 * N, INFL);
    D[0] = 0;

    while (!pq.empty()) {
        auto [nowd, now] = pq.top();
        pq.pop();
        bool done = now >= N;
        int nowv = now % N;

        if (D[now] < nowd) {
            continue;
        }

        for (auto [to, cost] : G[nowv]) {
            int nxt = to;
            if (done) {
                nxt += N;
            }
            if (D[nxt] > D[now] + cost) {
                D[nxt] = D[now] + cost;
                pq.push({D[nxt], nxt});
            }
        }

        if (T[nowv] && !done && nowd < S + E) {
            int nxt = now + N;
            ll nxtt = max(S + 1, nowd + 1);
            if (D[nxt] > nxtt) {
                D[nxt] = nxtt;
                pq.push({D[nxt], nxt});
            }
        }
    }

    ll ans = D[N * 2 - 1];
    if (ans == INFL) {
        ans = -1;
    }

    cout << ans << endl;
}
0