結果

問題 No.2805 Go to School
ユーザー 黒狗さん。黒狗さん。
提出日時 2024-06-18 19:35:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,231 bytes
コンパイル時間 1,799 ms
コンパイル使用メモリ 179,152 KB
実行使用メモリ 23,360 KB
最終ジャッジ日時 2024-07-04 21:13:23
合計ジャッジ時間 8,040 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 118 ms
9,052 KB
testcase_10 AC 368 ms
21,224 KB
testcase_11 AC 223 ms
14,628 KB
testcase_12 AC 325 ms
18,480 KB
testcase_13 AC 44 ms
6,272 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 161 ms
11,468 KB
testcase_18 AC 98 ms
8,900 KB
testcase_19 AC 250 ms
15,780 KB
testcase_20 AC 317 ms
20,280 KB
testcase_21 AC 134 ms
10,956 KB
testcase_22 AC 218 ms
14,604 KB
testcase_23 AC 217 ms
14,548 KB
testcase_24 AC 63 ms
8,684 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 13 ms
6,912 KB
testcase_28 AC 25 ms
7,680 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 232 ms
18,940 KB
testcase_32 AC 266 ms
18,784 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 106 ms
9,156 KB
testcase_36 AC 121 ms
10,112 KB
testcase_37 AC 221 ms
15,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Edge {
    long long to;
    long long cost;
};
vector<long long> dijkstra(const vector<vector<Edge>> &G, int s) {
    int N = G.size();
    vector<long long> dis(N, LLONG_MAX/16);
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        pair<long long, int> p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
    return dis;
}
int main() {
    ll N,M,L,S,E;
    cin >> N >> M >> L >> S >> E;
    vector<vector<Edge>> G(N);
    for (int i = 0; i < M; i++) {
        ll a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    vector<ll> T(L);
    for (int i = 0; i < L; i++) {
        cin >> T[i];
        T[i]--;
    }
    //家からダイクストラ
    vector<ll> dis1 = dijkstra(G, 0);
    //そもそもお腹が痛くなる前に学校につけるかどうか
    if (dis1[N-1] < S) {
        cout << dis1[N-1]<< endl;
        return 0;
    }
    //学校からダイクストラ
    vector<ll> dis2 = dijkstra(G, N-1);
    //それぞれのトイレについて間に合うかどうかを調べる
    ll ans = LLONG_MAX;
    for (int i = 0; i < L; i++) {
        ll t = T[i];
        ll time = dis1[t];
        //そもそもトイレの時間に間に合うかどうか
        if (time < S) {
            //トイレまで待つ+滞在期間
            time = S+1;
        }else if(S<=time and time < S+E) {
            //ちょうどお腹が痛いから滞在する
            time += 1;
        }else {
            //間に合わない...
            continue;
        }
        //トイレto学校
        time += dis2[t];
        ans = min(ans, time);
    }
    //answer
    if (ans == LLONG_MAX) {
        cout << -1 << endl;
    }else {
        cout << ans << endl;
    }
}
0