結果

問題 No.1473 おでぶなおばけさん
ユーザー srjywrdnprkt
提出日時 2023-06-19 15:19:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,003 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 203,320 KB
最終ジャッジ日時 2025-02-14 22:56:06
ジャッジサーバーID
(参考情報)
judge6 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll bfs(vector<vector<pair<ll, ll>>> &E, ll X){
 
    ll N = E.size();
    ll from, start=0;

    queue<ll> que;
    vector<ll> dist(N, 1e18);
 
    dist[start] = 0;
    que.push(start);
 
    while(!que.empty()){
        from = que.front();
        que.pop();
        for (auto [to, C] : E[from]){
            if (X > C) continue;
            if (dist[to] == 1e18){
                dist[to] = dist[from]+1;
                que.push(to);
            }
        }
    }

    return dist[N-1];
}

int main(){

    ll N, M, A, B, C, D;
    cin >> N >> M;
    vector<vector<pair<ll, ll>>> E(N);
    for (int i=0; i<M; i++){
        cin >> A >> B >> C;
        A--; B--;
        E[A].push_back({B, C});
        E[B].push_back({A, C});
    }

    ll l=0, r=1e9+1, c;

    while(r-l>1){
        c=(l+r)/2;
        D = bfs(E, c);
        if (D != 1e18) l=c;
        else r=c;
    }

    cout << l << " " << bfs(E, l) << endl;

    return 0;
}
0