結果

問題 No.1473 おでぶなおばけさん
ユーザー se1ka2se1ka2
提出日時 2021-04-09 21:43:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,371 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 80,772 KB
実行使用メモリ 8,440 KB
最終ジャッジ日時 2023-09-07 10:35:31
合計ジャッジ時間 7,164 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 51 ms
4,768 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 61 ms
4,580 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 75 ms
4,888 KB
testcase_42 AC 74 ms
4,864 KB
testcase_43 AC 90 ms
7,064 KB
testcase_44 AC 90 ms
7,008 KB
testcase_45 AC 91 ms
6,876 KB
testcase_46 AC 99 ms
6,856 KB
testcase_47 AC 120 ms
7,496 KB
testcase_48 AC 116 ms
7,224 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(s, t, 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