結果

問題 No.848 なかよし旅行
ユーザー betrue12betrue12
提出日時 2019-07-05 22:01:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,417 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 173,108 KB
実行使用メモリ 10,872 KB
最終ジャッジ日時 2024-04-16 07:19:12
合計ジャッジ時間 3,701 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
10,872 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 57 ms
6,784 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 5 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef pair<int64_t, int64_t> P;
const int64_t INF = 1e18;

vector<int64_t> dijkstra(int N, int s, vector<P> edges[]){
    vector<int64_t> dist(N, INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, s});
    while(que.size()){
        auto p = que.top(); que.pop();
        int i = p.second;
        int64_t d = p.first;
        if(d > dist[i]) continue;
        for(auto& e : edges[i]){
            int j = e.first;
            int64_t d2 = d + e.second;
            if(d2 < dist[j]){
                dist[j] = d2;
                que.push({d2, j});
            }
        }
    }
    return dist;
}

int main(){
    int N, M, A, B, T;
    cin >> N >> M >> A >> B >> T;
    A--; B--;
    vector<P> edges[2000];
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        edges[a-1].push_back({b-1, c});
        edges[b-1].push_back({a-1, c});
    }

    auto D0 = dijkstra(N, 0, edges);
    auto DA = dijkstra(N, A, edges);
    auto DB = dijkstra(N, B, edges);

    if(D0[A] + D0[B] + DA[B] <= T){
        cout << T << endl;
        return 0;
    }

    int64_t ans = -1;
    for(int i=0; i<N; i++){
        int64_t x = D0[i], y = max(DA[i], DB[i]);
        int64_t rest = T - 2*(x+y);
        if(rest >= 0){
            ans = max(ans, rest + 2*x);
        }
    }
    cout << ans << endl;
    return 0;
}
0