結果

問題 No.848 なかよし旅行
ユーザー sinsincoscossinsincoscos
提出日時 2019-07-05 23:54:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,255 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 79,056 KB
実行使用メモリ 8,016 KB
最終ジャッジ日時 2023-08-07 19:44:01
合計ジャッジ時間 2,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
7,272 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 38 ms
5,260 KB
testcase_12 AC 48 ms
5,472 KB
testcase_13 AC 60 ms
6,408 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 AC 53 ms
6,308 KB
testcase_16 AC 78 ms
7,904 KB
testcase_17 AC 53 ms
7,056 KB
testcase_18 AC 37 ms
5,008 KB
testcase_19 AC 38 ms
4,584 KB
testcase_20 AC 46 ms
4,376 KB
testcase_21 AC 58 ms
7,128 KB
testcase_22 AC 36 ms
7,388 KB
testcase_23 AC 45 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 79 ms
8,016 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <stdio.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pa;

struct edge{
    ll to,dist;
};

ll N,M,P,Q,T;
ll inf = 1e18;
vector<vector<edge>> v(2010);

void Dijkstra(int s,vector<ll>& dp){
    dp[s] = 0;
    vector<int> used(N+1,0);
    while(true){
        ll u = -1;
        for(int i=1;i<=N;i++){
            if(!used[i] && (u==-1 || dp[i]<dp[u])){
                u = i;
            }
        }
        if(u==-1) break;
        used[u] = 1;
        for(auto x:v[u]){
            dp[x.to] = min(dp[x.to],dp[u]+x.dist);
        }
    }
}

int main(){
    cin >> N >> M >> P >> Q >> T;
    ll a,b,c;
    for(int i=0;i<M;i++){
        scanf("%lld%lld%lld",&a,&b,&c);
        v[a].push_back({b,c});
        v[b].push_back({a,c});
    }
    vector<ll> dp1(N+1,inf),dp2(N+1,inf),dp3(N+1,inf);
    Dijkstra(1,dp1);
    Dijkstra(P,dp2);
    Dijkstra(Q,dp3);
    ll ans = -1;
    for(int i=1;i<N;i++) for(int j=i;j<=N;j++){
        ll t = dp1[i]+dp1[j]+max(dp2[i]+dp2[j],dp3[i]+dp3[j]);
        if(t<=T) ans = max(ans,T-max(dp2[i]+dp2[j],dp3[i]+dp3[j]));
    }
    if(2*(min(dp1[P],dp1[Q])+dp2[Q])<=T) ans = T;
    if(dp1[P]+dp1[Q]+dp2[Q]<=T) ans = T;
    cout << ans << endl;
}
0