結果

問題 No.1473 おでぶなおばけさん
ユーザー Manuel1024
提出日時 2021-04-27 22:44:03
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 1,172 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 80,476 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2024-07-06 17:43:14
合計ジャッジ時間 8,947 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;
constexpr int INF = 1001001001;

int isReachable(const vector<vector<P>> &G, int obakeW){
    vector<int> dist(G.size(), INF);
    queue<int> Q;
    Q.push(0);
    dist[0] = 0;
    while(Q.size()){
        int cur = Q.front(); Q.pop();
        for(auto &p: G[cur]){
            if(p.second >= obakeW && dist[p.first] == INF){
                dist[p.first] = dist[cur]+1;
                Q.push(p.first);
            }
        }
    }
    //cerr << limWeight << " " << dist[0] << " " << dist[1] << " " << dist[2] << endl;
    return dist[G.size()-1];
}

int main(){
    int n, m;
    cin >> n >> m;

    vector<vector<P>> G(n);
    for(int i = 0; i < m; i++){
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        G[s].push_back(make_pair(t, d));
        G[t].push_back(make_pair(s, d));
    }

    int ac = 0;
    int wa = INF;
    while(wa-ac > 1){
        int mid = (wa+ac)/2;
        int res = isReachable(G, mid);
        if(res == INF) wa = mid;
        else ac = mid;
    }

    cout << ac << " " << isReachable(G, ac) << endl;
    return 0;
}
0