結果

問題 No.848 なかよし旅行
ユーザー rogi52rogi52
提出日時 2022-10-12 22:21:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,309 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 211,304 KB
実行使用メモリ 10,804 KB
最終ジャッジ日時 2023-09-08 18:40:26
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

// g <- pair < v , cost > 
template < class T >
vector< T > dijkstra(vector<vector<pair<int, T>>> &graph, int s) {
    T INF = numeric_limits< T >::max();
    vector<T> dist(graph.size(), INF);
    priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T,int>>> q;
    q.push({dist[s] = T(0), s});
    while(!q.empty()){
        auto [uc, ui] = q.top(); q.pop();
        if(uc != dist[ui]) continue;
        for(auto [vi, vc] : graph[ui]) if(dist[vi] > uc + vc) 
            q.push({dist[vi] = uc + vc, vi});
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    ll N,M,P,Q,T; cin >> N >> M >> P >> Q >> T; P--, Q--;
    vector<vector<pair<int,ll>>> G(N);
    rep(_,M) {
        int a,b,c; cin >> a >> b >> c; a--, b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    auto dist0 = dijkstra(G, 0);
    auto distP = dijkstra(G, P);
    auto distQ = dijkstra(G, Q);
    ll ans = -1;
    rep(i,N) {
        if((dist0[i] + max(distP[i], distQ[i])) * 2 <= T) {
            ans = max(ans, T - max(distP[i], distQ[i]) * 2);
        }
    }

    if(dist0[P] + distP[Q] + distQ[0] <= T) ans = max(ans, T);
    cout << ans << endl;
}
0