結果

問題 No.1473 おでぶなおばけさん
ユーザー hitonanode
提出日時 2021-04-04 15:01:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 1,234 ms
コンパイル使用メモリ 97,300 KB
最終ジャッジ日時 2025-01-20 11:11:42
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

#include <atcoder/dsu>

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> edges;
    for (int e = 0; e < M; e++) {
        int s, t, d;
        cin >> s >> t >> d;
        edges.emplace_back(d, s - 1, t - 1);
    }

    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