結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 terry_u16terry_u16
提出日時 2021-04-09 22:34:15
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 3,567 ms
コンパイル使用メモリ 90,204 KB
実行使用メモリ 9,832 KB
最終ジャッジ日時 2023-09-07 12:05:33
合計ジャッジ時間 7,346 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 182 ms
9,260 KB
testcase_03 AC 131 ms
8,768 KB
testcase_04 AC 100 ms
6,676 KB
testcase_05 AC 41 ms
4,492 KB
testcase_06 AC 177 ms
8,980 KB
testcase_07 AC 163 ms
9,832 KB
testcase_08 AC 193 ms
9,756 KB
testcase_09 AC 150 ms
9,728 KB
testcase_10 AC 88 ms
5,208 KB
testcase_11 AC 87 ms
6,404 KB
testcase_12 AC 86 ms
5,760 KB
testcase_13 AC 52 ms
4,692 KB
testcase_14 AC 37 ms
4,376 KB
testcase_15 AC 73 ms
5,512 KB
testcase_16 AC 82 ms
5,416 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 11 ms
4,380 KB
testcase_19 AC 75 ms
5,788 KB
testcase_20 AC 100 ms
7,964 KB
testcase_21 AC 126 ms
6,788 KB
testcase_22 AC 97 ms
8,472 KB
testcase_23 AC 76 ms
8,272 KB
testcase_24 AC 75 ms
7,680 KB
testcase_25 AC 201 ms
8,476 KB
testcase_26 AC 209 ms
8,440 KB
testcase_27 AC 63 ms
4,832 KB
testcase_28 AC 184 ms
9,736 KB
testcase_29 AC 118 ms
7,088 KB
testcase_30 AC 155 ms
7,652 KB
testcase_31 AC 132 ms
9,292 KB
testcase_32 AC 134 ms
8,812 KB
testcase_33 AC 103 ms
7,824 KB
testcase_34 AC 57 ms
5,744 KB
testcase_35 AC 61 ms
5,680 KB
testcase_36 AC 108 ms
6,268 KB
testcase_37 AC 127 ms
7,996 KB
testcase_38 AC 23 ms
4,380 KB
testcase_39 AC 86 ms
4,928 KB
testcase_40 AC 82 ms
5,032 KB
testcase_41 AC 73 ms
5,020 KB
testcase_42 AC 75 ms
4,932 KB
testcase_43 AC 88 ms
7,020 KB
testcase_44 AC 95 ms
7,012 KB
testcase_45 AC 93 ms
7,020 KB
testcase_46 AC 104 ms
7,484 KB
testcase_47 AC 137 ms
8,484 KB
testcase_48 AC 123 ms
8,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>

const int INF = 1000111000;

int bfs(const std::vector<std::vector<std::pair<int, int>>> &graph, int from, int to, int weight)
{
    std::vector<int> distances(graph.size(), INF);
    std::queue<int> queue;

    distances[from] = 0;
    queue.push(from);

    while (!queue.empty())
    {
        int v = queue.front();
        queue.pop();

        for (auto &p : graph[v])
        {
            if (p.second >= weight && distances[p.first] == INF)
            {
                distances[p.first] = distances[v] + 1;
                queue.push(p.first);
            }
        }
    }

    return distances[to];
}

int main()
{
    int n, m;
    std::cin >> n >> m;
    std::vector<std::vector<std::pair<int, int>>> graph(n, std::vector<std::pair<int, int>>());

    for (size_t i = 0; i < m; i++)
    {
        int s, t, d;
        std::cin >> s >> t >> d;
        s--;
        t--;
        graph[s].push_back(std::make_pair(t, d));
        graph[t].push_back(std::make_pair(s, d));
    }

    int ok = 1;
    int ng = 1000000001;

    while (std::abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        int dist = bfs(graph, 0, n - 1, mid);

        if (dist < INF)
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }

    std::cout << ok << ' ' << bfs(graph, 0, n - 1, ok) << std::endl;
}
0