結果

問題 No.848 なかよし旅行
ユーザー kagasankagasan
提出日時 2019-07-23 19:53:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 171,708 KB
実行使用メモリ 11,284 KB
最終ジャッジ日時 2024-04-25 13:57:58
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
10,732 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,948 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 44 ms
6,940 KB
testcase_12 AC 58 ms
6,944 KB
testcase_13 AC 86 ms
8,040 KB
testcase_14 AC 19 ms
6,940 KB
testcase_15 AC 78 ms
7,940 KB
testcase_16 AC 145 ms
11,284 KB
testcase_17 AC 96 ms
8,812 KB
testcase_18 AC 42 ms
6,944 KB
testcase_19 AC 35 ms
6,940 KB
testcase_20 AC 9 ms
6,944 KB
testcase_21 AC 126 ms
10,204 KB
testcase_22 AC 141 ms
11,072 KB
testcase_23 AC 8 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 144 ms
9,724 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,944 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 a = 1; a <= N; a++){
        for(ll b = a; b <= N; b++){
            ll tmp = cost[0][a] + cost[0][b];
            ll P = cost[1][a] + cost[1][b];
            ll Q = cost[2][a] + cost[2][b];
            if(tmp + P + Q <= T)ans = T;
            else if(tmp + max(P, Q) <= T)ans = max(ans, T - max(P, Q));
        }
    }
    cout << ans << endl;
    
    return 0;    
}
0