結果

問題 No.1473 おでぶなおばけさん
ユーザー se1ka2se1ka2
提出日時 2021-04-09 21:50:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,371 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 80,236 KB
実行使用メモリ 9,652 KB
最終ジャッジ日時 2023-09-07 10:52:33
合計ジャッジ時間 7,840 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 161 ms
9,124 KB
testcase_03 AC 132 ms
8,312 KB
testcase_04 AC 105 ms
6,444 KB
testcase_05 AC 40 ms
4,456 KB
testcase_06 AC 181 ms
8,556 KB
testcase_07 AC 165 ms
9,348 KB
testcase_08 AC 213 ms
9,404 KB
testcase_09 AC 163 ms
9,320 KB
testcase_10 AC 83 ms
5,176 KB
testcase_11 AC 86 ms
6,332 KB
testcase_12 AC 84 ms
5,772 KB
testcase_13 AC 51 ms
4,736 KB
testcase_14 AC 37 ms
4,380 KB
testcase_15 AC 70 ms
5,428 KB
testcase_16 AC 78 ms
5,276 KB
testcase_17 AC 6 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 74 ms
5,780 KB
testcase_20 AC 101 ms
7,900 KB
testcase_21 AC 119 ms
6,696 KB
testcase_22 AC 97 ms
8,388 KB
testcase_23 AC 80 ms
7,764 KB
testcase_24 AC 79 ms
7,632 KB
testcase_25 AC 210 ms
8,020 KB
testcase_26 AC 213 ms
8,064 KB
testcase_27 AC 60 ms
5,004 KB
testcase_28 AC 190 ms
9,652 KB
testcase_29 AC 121 ms
7,012 KB
testcase_30 AC 160 ms
7,756 KB
testcase_31 AC 136 ms
9,432 KB
testcase_32 AC 137 ms
8,576 KB
testcase_33 AC 106 ms
7,620 KB
testcase_34 AC 56 ms
5,388 KB
testcase_35 AC 58 ms
5,404 KB
testcase_36 AC 105 ms
6,220 KB
testcase_37 AC 127 ms
7,584 KB
testcase_38 AC 23 ms
4,376 KB
testcase_39 AC 82 ms
4,832 KB
testcase_40 AC 78 ms
5,172 KB
testcase_41 AC 68 ms
4,832 KB
testcase_42 AC 70 ms
4,972 KB
testcase_43 AC 90 ms
7,040 KB
testcase_44 AC 88 ms
7,032 KB
testcase_45 AC 90 ms
6,864 KB
testcase_46 AC 109 ms
7,304 KB
testcase_47 AC 139 ms
7,992 KB
testcase_48 AC 121 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <queue>
using namespace std;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    std::vector<std::vector<Edge<T>>> g;
    
    WeightedGraph(){}
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

int dist(WeightedGraph<int> &g, int k){
    int n = g.n;
    int d[100005];
    for(int i = 0; i < n; i++) d[i] = -1;
    queue<int> que;
    d[0] = 0;
    que.push(0);
    while(que.size()){
        int u = que.front();
        que.pop();
        for(Edge<int> e : g.g[u]){
            if(e.cost < k) continue;
            int v = e.to;
            if(d[v] == -1){
                d[v] = d[u] + 1;
                que.push(v);
            }
        }
    }
    return d[n - 1];
}

int main()
{
    int n, m;
    cin >> n >> m;
    WeightedGraph<int> g(n);
    for(int i = 0; i < m; i++){
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        g.add_edge(s, t, d);
        g.add_edge(t, s, d);
    }
    int left = 0, right = 1000000009;
    while(right - left > 1){
        int mid = (right + left) / 2;
        if(dist(g, mid) >= 0) left = mid;
        else right = mid;
    }
    cout << left << " " << dist(g, left) << endl;
}
0