結果

問題 No.2387 Yokan Factory
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-21 22:03:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 448 ms / 5,000 ms
コード長 1,389 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 218,336 KB
実行使用メモリ 13,232 KB
最終ジャッジ日時 2023-10-21 22:05:18
合計ジャッジ時間 7,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 254 ms
13,232 KB
testcase_16 AC 169 ms
12,204 KB
testcase_17 AC 356 ms
12,236 KB
testcase_18 AC 344 ms
11,132 KB
testcase_19 AC 275 ms
9,152 KB
testcase_20 AC 230 ms
8,552 KB
testcase_21 AC 448 ms
10,812 KB
testcase_22 AC 208 ms
8,120 KB
testcase_23 AC 283 ms
9,088 KB
testcase_24 AC 126 ms
8,472 KB
testcase_25 AC 169 ms
6,700 KB
testcase_26 AC 315 ms
9,780 KB
testcase_27 AC 373 ms
10,496 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 4 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 4 ms
4,348 KB
testcase_35 AC 4 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<typename T> using pq = priority_queue<T, vector<T>, greater<T>>;

vector<ll> dijkstra(vector<vector<tuple<ll, ll, ll>>> &E, ll start, ll c){
 
    ll N = E.size();
    ll from, alt, d;

    pq<pair<ll, ll>> que;
    vector<ll> dist(N, 9e18);
    vector<bool> visit(N);
 
    dist[start] = 0;
    que.push({0, start});
 
    while(!que.empty()){
        tie(d, from) = que.top();
        que.pop();
        if (visit[from]) continue;
        visit[from] = 1;
        for (auto [to, C, D] : E[from]){
            if (D < c) continue;
            alt = d + C;
            if (alt < dist[to]){
                dist[to] = alt;
                que.push({dist[to], to});
            }
        }
    }
 
    return dist;
}

int main(){

    ll N, M, X, A, B, u, v;
    cin >> N >> M >> X;
    vector<vector<tuple<ll, ll, ll>>> E(N);
    for (int i=0; i<M; i++){
        cin >> u >> v >> A >> B;
        u--; v--;
        E[u].push_back({v, A, B});
        E[v].push_back({u, A, B});
    }

    ll l=0, r=1e9+1, c;
    while(r-l>1){
        c = (r+l)/2;
        vector<ll> dist = dijkstra(E, 0, c);
        if (dist[N-1] <= X) l = c;
        else r = c;
    }

    vector<ll> dist = dijkstra(E, 0, l);
    if (dist[N-1] > X){
        cout << -1 << endl;
        return 0;
    }

    cout << l << endl;

    return 0;
}
0