結果

問題 No.848 なかよし旅行
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-07-05 22:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,098 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 104,600 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-16 07:42:09
合計ジャッジ時間 3,109 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

constexpr int MAX_N = 2000;

vector< vector<Pll> > edges(MAX_N);

class Dijkstra {
    public: 
    ll d[MAX_N];
    priority_queue< Pll, vector<Pll>, greater<Pll> > que;
    ll start = -1;

    Dijkstra(ll start): start(start) {
        fill(d, d+MAX_N, 1LL<<60);
        d[start] = 0;
        que.push(Pll(0, start));

        while(!que.empty()){
            Pll v = que.top(); que.pop();
            if(d[v.second] < v.first) continue;
            for(Pll e: edges[v.second]){
                if(d[e.first] > d[v.second] + e.second){
                    d[e.first] = d[v.second] + e.second;
                    que.push(Pll(d[e.first], e.first));
                }
            }
        }
    }

    ll get(ll x) {
        return d[x];
    }
};

int main() {
    int n,m,p,q; ll t;
    cin >> n >> m >> p >> q >> t;
    --p; --q;
    int a,b; ll c;
    for(int i=0;i<m;++i){
        cin >> a >> b >> c;
        --a; --b;
        edges[a].emplace_back(b, c);
        edges[b].emplace_back(a, c);
    }

    Dijkstra d_0 = Dijkstra(0), d_p = Dijkstra(p), d_q = Dijkstra(q);

    ll ans = -1LL;
    if(d_0.get(p) + d_p.get(q) + d_q.get(0) <= t) {
        ans = t;
    } else {
        for(int r=0;r<n;++r) {
            ll tt = 2LL * (d_0.get(r) + max(d_p.get(r), d_q.get(r)));
            // cerr << r+1 << ": " << tt << endl;
            // cerr << d_0.get(r) << " " << d_p.get(r) << " " << d_q.get(r) << endl;
            if(tt > t) continue;
            ans = max(t-2*max(d_p.get(r), d_q.get(r)), ans);
        }
    }

    cout << ans << endl;


}
0