結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 hitonanodehitonanode
提出日時 2021-04-04 15:01:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 101,904 KB
実行使用メモリ 10,472 KB
最終ジャッジ日時 2023-08-27 19:41:55
合計ジャッジ時間 5,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 59 ms
9,932 KB
testcase_03 AC 48 ms
8,568 KB
testcase_04 AC 33 ms
6,772 KB
testcase_05 AC 12 ms
4,380 KB
testcase_06 AC 51 ms
8,352 KB
testcase_07 AC 60 ms
10,472 KB
testcase_08 AC 63 ms
10,428 KB
testcase_09 AC 61 ms
10,420 KB
testcase_10 AC 37 ms
4,656 KB
testcase_11 AC 37 ms
4,824 KB
testcase_12 AC 37 ms
4,808 KB
testcase_13 AC 25 ms
4,760 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 33 ms
4,880 KB
testcase_16 AC 36 ms
4,700 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 31 ms
4,884 KB
testcase_20 AC 42 ms
7,964 KB
testcase_21 AC 44 ms
5,880 KB
testcase_22 AC 52 ms
8,924 KB
testcase_23 AC 43 ms
8,760 KB
testcase_24 AC 43 ms
7,844 KB
testcase_25 AC 58 ms
8,616 KB
testcase_26 AC 60 ms
8,240 KB
testcase_27 AC 23 ms
4,708 KB
testcase_28 AC 63 ms
10,380 KB
testcase_29 AC 42 ms
6,392 KB
testcase_30 AC 49 ms
6,776 KB
testcase_31 AC 53 ms
10,064 KB
testcase_32 AC 42 ms
8,200 KB
testcase_33 AC 37 ms
7,604 KB
testcase_34 AC 20 ms
5,632 KB
testcase_35 AC 21 ms
5,080 KB
testcase_36 AC 43 ms
6,284 KB
testcase_37 AC 44 ms
8,008 KB
testcase_38 AC 10 ms
4,380 KB
testcase_39 AC 36 ms
4,796 KB
testcase_40 AC 37 ms
4,652 KB
testcase_41 AC 35 ms
4,672 KB
testcase_42 AC 34 ms
4,816 KB
testcase_43 AC 39 ms
7,836 KB
testcase_44 AC 39 ms
7,732 KB
testcase_45 AC 39 ms
7,716 KB
testcase_46 AC 45 ms
7,568 KB
testcase_47 AC 54 ms
8,620 KB
testcase_48 AC 49 ms
8,312 KB
権限があれば一括ダウンロードができます

ソースコード

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