結果

問題 No.848 なかよし旅行
ユーザー jelljell
提出日時 2019-07-06 16:10:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,487 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 186,436 KB
実行使用メモリ 8,960 KB
最終ジャッジ日時 2023-08-07 19:46:58
合計ジャッジ時間 3,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
8,960 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 15 ms
4,444 KB
testcase_12 AC 18 ms
4,812 KB
testcase_13 AC 25 ms
5,120 KB
testcase_14 AC 10 ms
4,376 KB
testcase_15 AC 23 ms
4,996 KB
testcase_16 AC 38 ms
5,636 KB
testcase_17 AC 27 ms
5,208 KB
testcase_18 AC 14 ms
4,376 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 7 ms
4,376 KB
testcase_21 AC 32 ms
5,260 KB
testcase_22 AC 31 ms
5,344 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 40 ms
5,868 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
using pll=pair<i64,i64>;
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<pll> 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[1][j],dist[2][i]+dist[2][j]);
            i64 tt=dist[0][i]+dist[0][j]+solo;
            if(tt<=T) {
                ans=max(ans,T-solo);
            }
        }
    }
    for(int i=0; i<n; ++i) {
        for(int j=0; j<n; ++j) {
            i64 solo=dist[1][i]+dist[2][j];
            // i64 tt=dist[0][]
        }
    }
    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