結果

問題 No.848 なかよし旅行
ユーザー ngtkanangtkana
提出日時 2020-03-29 12:35:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,187 bytes
コンパイル時間 1,993 ms
コンパイル使用メモリ 205,684 KB
実行使用メモリ 43,360 KB
最終ジャッジ日時 2023-08-30 18:41:52
合計ジャッジ時間 9,955 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
void cmn(lint&x,lint y){if(x>y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,m,p,q,T;std::cin>>n>>m>>p>>q>>T;p--,q--;
    lint inf=std::numeric_limits<lint>::max();
    std::vector<std::vector<lint>>table(n,std::vector<lint>(n,inf));
    auto dist=[&](lint i,lint j)->lint&{return table.at(i).at(j);};
    for(lint i=0;i<n;i++)dist(i,i)=0;
    while(m--){
        lint a,b,c;std::cin>>a>>b>>c;a--,b--;
        dist(a,b)=c;
        dist(b,a)=c;
    }
    for(lint i=0;i<n;i++){
    for(lint j=0;j<n;j++){
    for(lint k=0;k<n;k++){
        if(dist(j,i)==inf)continue;
        if(dist(i,k)==inf)continue;
        cmn(dist(j,k),dist(j,i)+dist(i,k));
    }}}
    if(dist(0,p)+dist(p,q)+dist(q,0)<=T){
        std::cout<<T<<'\n';
        return 0;
    }
    lint min=inf;
    for(lint i=0;i<n;i++){
    for(lint j=0;j<n;j++){
        lint t=std::max(dist(i,p)+dist(p,j),dist(i,q)+dist(q,j));
        if(T<dist(0,i)+t+dist(j,0))continue;
        cmn(min,t);
    }}
    std::cout<<(min==inf?-1:T-min)<<'\n';
}
0