結果

問題 No.848 なかよし旅行
ユーザー kappybarkappybar
提出日時 2020-04-09 14:06:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,744 bytes
コンパイル時間 1,705 ms
コンパイル使用メモリ 179,328 KB
実行使用メモリ 15,180 KB
最終ジャッジ日時 2023-10-11 08:08:08
合計ジャッジ時間 6,894 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
using Pll = pair<ll,ll>;
const ll INF = 1e18;
const int MOD = 1000000007;

ll v = 2005,e;
vector<vector<pair<ll,ll>>> graph(v,vector<pair<ll,ll>>());

vector<ll> dijkstra(ll start){
    vector<ll> shortest(v);
    vector<bool> visited(v,false);
    priority_queue<pair<ll,ll>,vector<pair<ll ,ll>>,greater<pair<ll,ll>>> pq;
    pq.push(make_pair(0,start));
    while (!pq.empty()){
        pair<ll,ll> now = pq.top();
        pq.pop();
        ll cost,node;
        tie(cost,node) = now;
        if(visited[node]){
            continue;
        }else{
            shortest[node] = cost;
            visited[node] = true;
            for(pair<ll,ll> next:graph[node]){
                ll next_cost,next_node;
                tie(next_cost,next_node) = next;
                pq.push(make_pair(cost+next_cost,next_node));
            }
        }
    }
    return shortest;
}

int main(){
    int p,q;
    ll time;
    cin >> v >> e >> p >> q >> time;
    --p;--q;
    rep(i,e){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        --a;--b;
        graph[a].push_back(Pll(c,b));
        graph[b].push_back(Pll(c,a));
    }
    vector<ll> dis_zero = dijkstra(0);
    vector<ll> dis_p = dijkstra(p);
    vector<ll> dis_q = dijkstra(q);
    if(dis_zero[p] + dis_p[q] + dis_zero[q] <= time){
        cout << time << endl;
        return 0;
    }
    ll ans = -1;
    rep(i,v){
        ll s = dis_zero[i];
        ll t = dis_p[i];
        ll u = dis_q[i];
        if(2*(s+t) <= time && 2*(s+u) <= time){
            ans = max(ans,time - 2*max(t,u));
        }
    }
    cout << ans << endl;
    return 0;
}
0