結果

問題 No.1473 おでぶなおばけさん
ユーザー MisterMister
提出日時 2021-04-09 21:32:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,129 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 103,516 KB
実行使用メモリ 11,528 KB
最終ジャッジ日時 2023-09-07 10:03:05
合計ジャッジ時間 5,726 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 63 ms
10,776 KB
testcase_03 AC 46 ms
8,864 KB
testcase_04 AC 35 ms
7,696 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 51 ms
8,868 KB
testcase_07 AC 68 ms
11,524 KB
testcase_08 AC 69 ms
11,484 KB
testcase_09 AC 66 ms
11,528 KB
testcase_10 AC 35 ms
4,432 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 36 ms
4,376 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 32 ms
4,380 KB
testcase_16 AC 35 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 30 ms
4,880 KB
testcase_20 AC 41 ms
8,044 KB
testcase_21 AC 45 ms
6,496 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 54 ms
8,304 KB
testcase_27 WA -
testcase_28 AC 64 ms
11,136 KB
testcase_29 WA -
testcase_30 AC 50 ms
7,012 KB
testcase_31 AC 59 ms
11,240 KB
testcase_32 AC 43 ms
8,824 KB
testcase_33 AC 37 ms
8,136 KB
testcase_34 AC 22 ms
5,944 KB
testcase_35 AC 21 ms
5,132 KB
testcase_36 WA -
testcase_37 AC 47 ms
8,868 KB
testcase_38 WA -
testcase_39 AC 35 ms
4,376 KB
testcase_40 AC 35 ms
4,424 KB
testcase_41 AC 33 ms
4,472 KB
testcase_42 AC 33 ms
4,384 KB
testcase_43 AC 39 ms
8,220 KB
testcase_44 AC 39 ms
8,156 KB
testcase_45 AC 39 ms
8,172 KB
testcase_46 AC 49 ms
8,848 KB
testcase_47 AC 61 ms
9,932 KB
testcase_48 AC 53 ms
9,196 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);
    Graph<> graph(n);

    for (auto [d, u, v] : es) {
        dsu.merge(u, v);
        graph.span(false, u, v);

        if (dsu.same(0, n - 1)) {
            cout << d << " " << bfs(graph, 0)[n - 1] << "\n";
            return;
        }
    }
}

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

    solve();

    return 0;
}
0