結果

問題 No.1473 おでぶなおばけさん
ユーザー hitonanode
提出日時 2021-04-04 15:20:36
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,609 bytes
コンパイル時間 433 ms
コンパイル使用メモリ 40,200 KB
最終ジャッジ日時 2025-01-20 11:13:22
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:11:10: fatal error: testlib.h: No such file or directory
   11 | #include "testlib.h"
      |          ^~~~~~~~~~~
compilation terminated.

ソースコード

diff #

// Input validator
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

#include <atcoder/dsu>
#include "testlib.h"

int main(int argc, char **argv) {
    registerValidation(argc, argv);

    const int N = inf.readInt(2, 100000);
    inf.readSpace();
    const int M = inf.readInt(N - 1, 100000);
    inf.readEoln();

    atcoder::dsu dsu_validator(N);

    vector<tuple<int, int, int>> edges;
    for (int e = 0; e < M; e++) {
        int s = inf.readInt(1, N);
        inf.readSpace();
        int t = inf.readInt(1, N);
        inf.readSpace();
        int d = inf.readInt(1, 1000000000);
        inf.readEoln();
        assert(s != t);
        edges.emplace_back(d, s - 1, t - 1);
        dsu_validator.merge(s - 1, t - 1);
    }
    inf.readEof();

    assert(dsu_validator.size(0) == N);

    sort(edges.rbegin(), edges.rend());

    atcoder::dsu uf(N);
    int ret = 1 << 30;
    for (auto [d, s, t] : edges) {
        if (!uf.same(0, N - 1)) ret = min(ret, d);
        uf.merge(s, t);
    }

    vector<vector<int>> to(N);
    for (auto [w, s, t] : edges) {
        if (w >= ret) to[s].push_back(t), to[t].push_back(s);
    }

    vector<int> dist(N, 1 << 30);
    dist[0] = 0;

    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        const int now = q.front();
        q.pop();
        for (auto nxt : to[now]) {
            if (dist[nxt] > dist[now] + 1) {
                dist[nxt] = dist[now] + 1;
                q.push(nxt);
            }
        }
    }
    cout << ret << ' ' << dist.back() << '\n';
}
0