結果

問題 No.848 なかよし旅行
ユーザー nemutainemutai
提出日時 2023-03-31 10:56:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,318 bytes
コンパイル時間 3,715 ms
コンパイル使用メモリ 177,384 KB
実行使用メモリ 10,848 KB
最終ジャッジ日時 2023-10-23 22:56:43
合計ジャッジ時間 8,040 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
10,848 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 34 ms
5,440 KB
testcase_12 AC 45 ms
5,804 KB
testcase_13 AC 61 ms
6,700 KB
testcase_14 AC 19 ms
4,352 KB
testcase_15 AC 57 ms
6,596 KB
testcase_16 AC 99 ms
8,308 KB
testcase_17 AC 69 ms
7,372 KB
testcase_18 AC 34 ms
5,300 KB
testcase_19 AC 29 ms
4,868 KB
testcase_20 AC 12 ms
4,348 KB
testcase_21 AC 84 ms
7,468 KB
testcase_22 AC 91 ms
7,516 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 105 ms
8,284 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define all(v) v.begin(),v.end()
using ll = long long;
using ull = unsigned long long;
using vll=vector<ll>;
const ll INF=1ll<<60;
using vp=vector<pair<ll, ll>>;
using P = pair<ll,ll>;
using vvll = vector<vector<P>>;


ll N,M,p,Q,T;

vll dik(ll s,vvll &ab){
    vll dist(N,INF);
    priority_queue<P,vector<P>,greater<P>>q;
    dist[s]=0;
    q.push({0,s});
    while(!q.empty()){
        auto x=q.top();q.pop();
        if(dist[x.second]<x.first)continue;
        for(auto to:ab[x.second]){
            if(dist[to.second]<=to.first+x.first)continue;
            dist[to.second]=to.first+x.first;
            q.push({dist[to.second],to.second});
        }
    }
    return dist;
}

int main(){
    cin>>N>>M>>p>>Q>>T;
    p--;Q--;
    vvll ab(N);
    for(int i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        ab[a].push_back({c,b});
        ab[b].push_back({c,a});
    }
    vll dist=dik(0,ab);
    vll distp=dik(p,ab);
    vll distq=dik(Q,ab);
    ll ans=-1;
    if(dist[p]+distp[Q]+dist[Q]<=T)ans=max(ans,T);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(max(distp[i]+distp[j],distq[i]+distq[j])+dist[i]+dist[j]<=T)ans=max(ans,T-(max(distp[i]+distp[j],distq[i]+distq[j])));
        }
    }
    cout << ans << endl;
}
0