結果

問題 No.848 なかよし旅行
ユーザー Y17Y17
提出日時 2019-07-05 22:38:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,590 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 166,920 KB
実行使用メモリ 14,604 KB
最終ジャッジ日時 2024-04-16 07:51:41
合計ジャッジ時間 4,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

#define int long long

vector<pair<int, int> > graph[2010];

int n, m, p, q, t;
int dist[2010][2010];

void min_dist(int st){
    for(int i = 0;i < n;i++){
        dist[st][i] = LLONG_MAX/4;
    }

    dist[st][st] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
    que.push(make_pair(0, st));

    while(!que.empty()){
        int cost = que.top().first;
        int idx = que.top().second;
        que.pop();

        for(int i = 0;i < graph[idx].size();i++){
            int next = graph[idx][i].first;
            int ncost = graph[idx][i].second + cost;
            if(dist[st][next] > ncost){
                dist[st][next] = ncost;
                que.push(make_pair(ncost, next));
            }
        }
    }

    return;
}

signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m >> p >> q >> t;

    p--;
    q--;

    int a, b, c;
    for(int i = 0;i < m;i++){
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a].push_back(make_pair(b, c));
        graph[b].push_back(make_pair(a, c));
    }

    min_dist(0);
    min_dist(p);
    min_dist(q);


    if(dist[0][p] + dist[p][q] + dist[q][0] <= t){
        cout << t << endl;
        return 0;
    }

    int ans = -1;
    for(int i = 0;i < n;i++){
        if(i != q && i != p){
            int ma = max(dist[q][i]*2, dist[p][i]*2);
            if(dist[0][i]*2 + ma <= t){
                ans = max(ans, t-ma);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

0