結果

問題 No.1473 おでぶなおばけさん
ユーザー MisterMister
提出日時 2021-04-09 21:33:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,207 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 103,104 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2023-09-07 10:09:07
合計ジャッジ時間 6,093 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 68 ms
10,740 KB
testcase_03 AC 49 ms
8,852 KB
testcase_04 AC 34 ms
7,532 KB
testcase_05 AC 13 ms
4,384 KB
testcase_06 AC 52 ms
9,076 KB
testcase_07 AC 67 ms
11,496 KB
testcase_08 AC 67 ms
11,460 KB
testcase_09 AC 71 ms
11,556 KB
testcase_10 AC 36 ms
4,392 KB
testcase_11 AC 36 ms
4,384 KB
testcase_12 AC 36 ms
4,384 KB
testcase_13 AC 23 ms
4,380 KB
testcase_14 AC 18 ms
4,380 KB
testcase_15 AC 32 ms
4,384 KB
testcase_16 AC 34 ms
4,384 KB
testcase_17 AC 4 ms
4,384 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 31 ms
5,040 KB
testcase_20 AC 42 ms
8,044 KB
testcase_21 AC 45 ms
6,480 KB
testcase_22 AC 57 ms
10,160 KB
testcase_23 AC 48 ms
9,364 KB
testcase_24 AC 47 ms
9,312 KB
testcase_25 AC 62 ms
9,896 KB
testcase_26 AC 65 ms
10,156 KB
testcase_27 AC 25 ms
5,596 KB
testcase_28 AC 67 ms
11,220 KB
testcase_29 AC 41 ms
6,476 KB
testcase_30 AC 48 ms
7,044 KB
testcase_31 AC 57 ms
11,228 KB
testcase_32 AC 42 ms
8,920 KB
testcase_33 AC 37 ms
8,048 KB
testcase_34 AC 22 ms
5,944 KB
testcase_35 AC 21 ms
5,100 KB
testcase_36 AC 46 ms
8,048 KB
testcase_37 AC 47 ms
8,920 KB
testcase_38 AC 11 ms
4,396 KB
testcase_39 AC 35 ms
4,380 KB
testcase_40 AC 35 ms
4,384 KB
testcase_41 AC 32 ms
4,388 KB
testcase_42 AC 32 ms
4,448 KB
testcase_43 AC 38 ms
8,156 KB
testcase_44 AC 38 ms
8,276 KB
testcase_45 AC 39 ms
8,164 KB
testcase_46 AC 51 ms
8,876 KB
testcase_47 AC 60 ms
9,948 KB
testcase_48 AC 52 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/bfs.hpp"

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/graph.hpp"

#include <vector>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;

    Edge() = default;
    Edge(int src, int dst, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return cost > e.cost; }
};

template <class Cost = int>
struct Graph : public std::vector<std::vector<Edge<Cost>>> {
    using std::vector<std::vector<Edge<Cost>>>::vector;

    void span(bool direct, int src, int dst, Cost cost = 1) {
        (*this)[src].emplace_back(src, dst, cost);
        if (!direct) (*this)[dst].emplace_back(dst, src, cost);
    }
};
#line 4 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Graph/bfs.hpp"

#include <queue>

template <class Cost>
std::vector<Cost> bfs(const Graph<Cost>& graph, int s) {
    std::vector<Cost> dist(graph.size(), -1);
    dist[s] = 0;
    std::queue<int> que;
    que.push(s);

    while (!que.empty()) {
        auto v = que.front();
        que.pop();

        for (const auto& e : graph[v]) {
            if (dist[e.dst] != -1) continue;
            dist[e.dst] = dist[v] + e.cost;
            que.push(e.dst);
        }
    }

    return dist;
}
#line 2 "main.cpp"
#include <atcoder/dsu>
#include <iostream>
#include <algorithm>
#line 6 "main.cpp"
#include <tuple>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<tuple<int, int, int>> es(m);
    for (auto& [d, u, v] : es) {
        cin >> u >> v >> d;
        --u, --v;
    }

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

    atcoder::dsu dsu(n);
    int nd = 0;
    for (auto [d, u, v] : es) {
        dsu.merge(u, v);
        if (dsu.same(0, n - 1)) {
            nd = d;
            break;
        }
    }

    Graph<> graph(n);
    for (auto [d, u, v] : es) {
        if (d >= nd) graph.span(false, u, v);
    }
    cout << nd << " " << bfs(graph, 0)[n - 1] << "\n";
}

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

    solve();

    return 0;
}
0