結果

問題 No.848 なかよし旅行
ユーザー kagasankagasan
提出日時 2019-07-23 19:23:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,439 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 171,092 KB
実行使用メモリ 11,284 KB
最終ジャッジ日時 2024-04-16 09:45:40
合計ジャッジ時間 4,459 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
10,732 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 88 ms
8,040 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 long long ll;
typedef pair<ll, ll>P;

ll N, M, T;
ll st[3] = {1, 0, 0};
vector<P>path[2020];
ll cost[3][2020];

int main(){

    cin >> N >> M >> st[1] >> st[2] >> T;
    for(ll i = 0; i < M; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        path[a].push_back(P(b, c));
        path[b].push_back(P(a, c));
    }
    for(ll i = 0; i < 3; i++){
        for(ll j = 0; j < 2020; j++)cost[i][j] = -1;
        priority_queue<P, vector<P>, greater<P> >Q;
        Q.push(P(0, st[i]));
        while(!Q.empty()){
            ll idx = Q.top().second;
            ll cst = Q.top().first;
            Q.pop();
            if(cost[i][idx] >= 0)continue;
            cost[i][idx] = cst;
            for(ll j = 0; j < path[idx].size(); j++){
                ll nxt = path[idx][j].first;
                ll w = path[idx][j].second;
                if(cost[i][nxt] < 0){
                    Q.push(P(cst + w, nxt));
                }
            }
        }
    }
    ll ans = -1;
    for(ll i = 1; i <= N; i++){
        // cout << cost[0][i] << ", " << cost[1][i] << ", " << cost[2][i] << endl;
        if(T >= 2 * (cost[0][i] + cost[1][i] + cost[2][i])){
            ans = T;
        }
        else if(T >= 2 * cost[0][i] + 2 * max(cost[1][i], cost[2][i])){
            ans = max(ans, T - 2 * max(cost[1][i], cost[2][i]));
        }
    }
    cout << ans << endl;
    
    return 0;    
}
0