結果

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

ソースコード

diff #

// WA となるべき
#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;
    vector<vector<int>> to(N);

    for (auto [d, s, t] : edges) {
        if (!uf.same(0, N - 1)) {
            ret = min(ret, d);
            to[s].push_back(t), to[t].push_back(s); // 辺の追加漏れの可能性がある
        }
        uf.merge(s, t);
    }

    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