結果

問題 No.1473 おでぶなおばけさん
ユーザー 👑 hitonanodehitonanode
提出日時 2021-04-04 18:20:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,283 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 91,788 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2023-08-27 19:13:51
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 104 ms
9,672 KB
testcase_03 AC 76 ms
8,704 KB
testcase_04 AC 53 ms
6,688 KB
testcase_05 AC 22 ms
4,496 KB
testcase_06 AC 107 ms
9,172 KB
testcase_07 AC 93 ms
9,800 KB
testcase_08 AC 112 ms
9,828 KB
testcase_09 AC 99 ms
9,856 KB
testcase_10 AC 42 ms
5,644 KB
testcase_11 AC 43 ms
6,628 KB
testcase_12 AC 42 ms
5,904 KB
testcase_13 AC 27 ms
5,204 KB
testcase_14 AC 19 ms
4,380 KB
testcase_15 AC 37 ms
5,580 KB
testcase_16 AC 39 ms
5,248 KB
testcase_17 AC 5 ms
4,384 KB
testcase_18 AC 6 ms
4,384 KB
testcase_19 AC 49 ms
5,816 KB
testcase_20 AC 66 ms
8,068 KB
testcase_21 AC 82 ms
7,048 KB
testcase_22 AC 56 ms
8,772 KB
testcase_23 AC 45 ms
8,148 KB
testcase_24 AC 42 ms
7,772 KB
testcase_25 AC 57 ms
8,592 KB
testcase_26 AC 59 ms
8,692 KB
testcase_27 AC 20 ms
5,088 KB
testcase_28 AC 75 ms
9,716 KB
testcase_29 AC 57 ms
7,508 KB
testcase_30 AC 66 ms
7,952 KB
testcase_31 AC 73 ms
9,696 KB
testcase_32 AC 94 ms
9,204 KB
testcase_33 AC 57 ms
7,764 KB
testcase_34 AC 30 ms
5,544 KB
testcase_35 AC 33 ms
5,608 KB
testcase_36 AC 40 ms
6,692 KB
testcase_37 AC 43 ms
7,768 KB
testcase_38 AC 9 ms
4,384 KB
testcase_39 AC 40 ms
5,348 KB
testcase_40 AC 40 ms
5,388 KB
testcase_41 AC 39 ms
5,476 KB
testcase_42 AC 38 ms
5,472 KB
testcase_43 AC 44 ms
7,544 KB
testcase_44 AC 45 ms
7,496 KB
testcase_45 AC 45 ms
7,408 KB
testcase_46 AC 49 ms
7,564 KB
testcase_47 AC 64 ms
8,552 KB
testcase_48 AC 69 ms
8,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 二分探索解 (AC)
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

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

    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> to(N);
    vector<int> ds;
    for (int e = 0; e < M; e++) {
        int s, t, d;
        cin >> s >> t >> d;
        s--, t--;
        to[s].emplace_back(t, d);
        to[t].emplace_back(s, d);
        ds.push_back(d);
    }

    sort(ds.begin(), ds.end());
    ds.erase(unique(ds.begin(), ds.end()), ds.end());

    int ok = 0, ng = ds.size();

    auto solve = [&](int th) -> int {
        vector<int> dist(N, 1 << 30);
        dist[0] = 0;
        queue<int> q;
        q.push(0);
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (auto [nxt, w] : to[now]) {
                if (w >= th and dist[nxt] > dist[now] + 1) {
                    dist[nxt] = dist[now] + 1;
                    q.push(nxt);
                }
            }
        }
        return dist.back();
    };

    while (ng - ok > 1) {
        const int c = (ok + ng) / 2;
        auto ret = solve(ds[c]);
        (ret == 1 << 30 ? ng : ok) = c;
    }
    cout << ds[ok] << ' ' << solve(ds[ok]) << '\n';
}
0