結果

問題 No.1473 おでぶなおばけさん
ユーザー houren
提出日時 2021-12-01 22:43:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 1,803 ms
コンパイル使用メモリ 179,624 KB
実行使用メモリ 9,656 KB
最終ジャッジ日時 2024-07-05 00:26:38
合計ジャッジ時間 8,544 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:43:26: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   43 |     cout << ok << " " << ans << endl;
      |                          ^~~
main.cpp:19:34: note: 'ans' was declared here
   19 |     int ok = 0, ng = 1000000001, ans;
      |                                  ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<P>> to(n);
    rep(i,m){
        int s,t,d;
        cin >> s >> t >> d;
        s--; t--;
        to[s].push_back(make_pair(t,d));
        to[t].push_back(make_pair(s,d));
    }
    int ok = 0, ng = 1000000001, ans;
    while(ng-ok != 1){
        int md = (ng + ok) / 2;
        vector<int> dist(n,-1);
        dist[0] = 0;
        queue<int> que;
        que.push(0);
        while(que.size()){
            int now = que.front();
            que.pop();
            for(auto p:to[now]){
                int x,w;
                tie(x,w) = p;
                if(w < md || dist[x] != -1) continue;
                dist[x] = dist[now] + 1;
                que.push(x);
            }
        }
        if(dist[n-1] != -1){
            ok = md;
            ans = dist[n-1];
        }
        else ng = md;
    }
    cout << ok << " " << ans << endl;
    return 0;
}
0