結果

問題 No.848 なかよし旅行
ユーザー rpy3cpprpy3cpp
提出日時 2019-09-09 17:47:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,709 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 177,800 KB
実行使用メモリ 6,924 KB
最終ジャッジ日時 2023-09-10 21:49:31
合計ジャッジ時間 3,657 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
6,924 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 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,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 19 ms
4,748 KB
testcase_13 AC 26 ms
4,972 KB
testcase_14 AC 10 ms
4,380 KB
testcase_15 AC 23 ms
4,936 KB
testcase_16 AC 39 ms
5,756 KB
testcase_17 AC 28 ms
5,280 KB
testcase_18 AC 15 ms
4,380 KB
testcase_19 AC 13 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 32 ms
5,420 KB
testcase_22 AC 32 ms
5,424 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 43 ms
5,764 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

constexpr int INF = 1'000'000'009;

struct Edge{
    int to;
    int cost;
    Edge(int to, int cost):to(to), cost(cost) {}
};

vector<int> dijkstra(int start, const vector<vector<Edge>> &Es){
    int N = Es.size();
    vector<int> dist(N, INF);
    dist[start] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, start));
    while (not pq.empty()){
        int d, v;
        tie(d, v) = pq.top();
        pq.pop();
        if (d > dist[v]) continue;
        dist[v] = d;
        for (auto &uc : Es[v]){
            int u = uc.to;
            int new_d = d + uc.cost;
            if (new_d < dist[u]){
                dist[u] = new_d;
                pq.push(make_pair(new_d, u));
            }
        }
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, P, Q, T;
    cin >> N >> M >> P >> Q >> T;
    --P;
    --Q;
    vector<vector<Edge>> Es(N, vector<Edge>());
    for (int m = 0; m < M; ++m){
        int a, b, c;
        cin >> a >> b >> c;
        Es[a - 1].emplace_back(Edge(b - 1, c));
        Es[b - 1].emplace_back(Edge(a - 1, c));
    }
    auto dist0 = dijkstra(0, Es);
    auto distP = dijkstra(P, Es);
    auto distQ = dijkstra(Q, Es);
    if (dist0[P] + distP[Q] + distQ[0] <= T){
        cout << T << endl;
        return 0;
    }
    long long record = -1;
    for (int r = 0; r < N; ++r){
        for (int s = r; s < N; ++s){
        long long t = max(distP[r] + distP[s], distQ[r] + distQ[s]);
        if (dist0[r] + dist0[s] + t <= T) record = max(record, T - t);
        }
    }
    cout << record << endl;
    return 0;
}
0