結果

問題 No.848 なかよし旅行
ユーザー jelljell
提出日時 2019-07-06 11:48:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,313 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 183,300 KB
実行使用メモリ 6,984 KB
最終ジャッジ日時 2024-04-16 08:30:03
合計ジャッジ時間 3,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
template <class T> constexpr T inf=numeric_limits<T>::max() / (T)2;
template <class T> using minheap=priority_queue<T,vector<T>,greater<T>>;
#define fir first
#define sec second
#define mkp make_pair
#define mkt make_tuple
#define emb emplace_back
#define emp emplace
#define all(v) begin(v),end(v)
void ios_untie() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}
void file_setup() {
    if(!freopen("stderr.txt","wt",stderr)) {
        std::cerr << "Failed to open the stderr file\n";
        freopen("CON","wt",stderr);
    }
    if(!freopen("stdout.txt","wt",stdout)) {
        std::cerr << "Failed to open the stdout file\n";
        freopen("CON","wt",stdout);
    }
    if(!freopen("stdin.txt","rt",stdin)) {
        std::cerr << "Failed to open the stdin file.\n";
        freopen("CON","rt",stdin);
    }
}
i64 binry(i64 ok, i64 ng, const function<bool(i64)> &f) {
    while(abs(ok-ng)>1) {
        i64 mid=(ok+ng)/2;
        (f(mid) ? ok : ng) = mid;
    }
    return ok;
}

int n,P,Q,T;
vector<pii> g[2010];
i64 dist[3][2010];

void solve() {
    size_t indx=0;
    for(int s:{0,P,Q}) {
        auto dis=dist[indx];
        fill(dis,dis+n,inf<i64>);
        minheap<pii> que;
        que.emplace(dis[s]=0,s);
        while(!que.empty()) {
            i64 d; int v; tie(d,v)=que.top(); que.pop();
            if(d!=dis[v]) continue;
            for(auto &e:g[v]) {
                if(d+e.sec<dis[e.fir]) {
                    que.emplace(dis[e.fir]=d+e.sec,e.fir);
                }
            }
        }
        indx++;
    }
    i64 ans=-1;
    for(int i=0; i<n; ++i) {
        for(int j=0; j<=i; ++j) {
            i64 solo=max(dist[1][i],dist[2][i])+max(dist[1][j],dist[2][j]);
            i64 tt=dist[0][i]+dist[0][j]+solo;
            if(tt<=T) {
                ans=max(ans,T-solo);
            }
        }
    }
    if(dist[0][P]+dist[0][Q]+dist[1][Q]<=T) ans=T;
    cout<<ans<<endl;
}

signed main() {
    ios_untie();
#ifdef LOCAL
    file_setup();
#endif

    int m;
    cin>>n>>m>>P>>Q>>T;
    P--,Q--;
    while(m--) {
        int u,v,c; cin>>u>>v>>c;
        u--,v--;
        g[u].emplace_back(v,c);
        g[v].emplace_back(u,c);
    }
    solve();
}
0