結果

問題 No.1473 おでぶなおばけさん
ユーザー terry_u16
提出日時 2021-04-09 22:34:15
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 210 ms / 2,000 ms
コード長 1,408 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 125,952 KB
実行使用メモリ 10,036 KB
最終ジャッジ日時 2024-06-25 06:11:42
合計ジャッジ時間 7,397 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

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