結果

問題 No.1473 おでぶなおばけさん
ユーザー KudeKude
提出日時 2021-04-09 22:03:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,487 bytes
コンパイル時間 4,622 ms
コンパイル使用メモリ 270,348 KB
実行使用メモリ 10,608 KB
最終ジャッジ日時 2023-09-07 11:20:27
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 58 ms
9,932 KB
testcase_03 AC 45 ms
8,656 KB
testcase_04 AC 32 ms
7,120 KB
testcase_05 AC 12 ms
4,512 KB
testcase_06 AC 51 ms
8,564 KB
testcase_07 AC 62 ms
10,524 KB
testcase_08 AC 61 ms
10,608 KB
testcase_09 AC 62 ms
10,568 KB
testcase_10 AC 34 ms
4,380 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 34 ms
4,640 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 16 ms
4,380 KB
testcase_15 AC 31 ms
4,380 KB
testcase_16 AC 33 ms
4,384 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 27 ms
4,964 KB
testcase_20 AC 37 ms
7,896 KB
testcase_21 AC 40 ms
6,220 KB
testcase_22 AC 44 ms
8,884 KB
testcase_23 AC 39 ms
8,648 KB
testcase_24 AC 38 ms
7,824 KB
testcase_25 AC 47 ms
8,684 KB
testcase_26 AC 50 ms
8,456 KB
testcase_27 AC 19 ms
4,792 KB
testcase_28 AC 56 ms
10,508 KB
testcase_29 AC 34 ms
6,340 KB
testcase_30 AC 40 ms
6,864 KB
testcase_31 AC 53 ms
10,232 KB
testcase_32 AC 40 ms
8,360 KB
testcase_33 AC 34 ms
7,628 KB
testcase_34 AC 20 ms
5,460 KB
testcase_35 AC 20 ms
4,940 KB
testcase_36 AC 37 ms
6,428 KB
testcase_37 AC 39 ms
8,152 KB
testcase_38 AC 9 ms
4,380 KB
testcase_39 AC 34 ms
4,376 KB
testcase_40 AC 34 ms
4,604 KB
testcase_41 AC 32 ms
4,436 KB
testcase_42 AC 32 ms
4,380 KB
testcase_43 AC 36 ms
7,856 KB
testcase_44 AC 36 ms
7,808 KB
testcase_45 AC 37 ms
7,724 KB
testcase_46 AC 43 ms
7,644 KB
testcase_47 AC 53 ms
8,616 KB
testcase_48 AC 47 ms
8,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    struct Edge {
        int u, v, w;
        bool operator<(const Edge& x) const {
            return w < x.w;
        }
    };
    vector<Edge> es(m);
    for(auto& e: es) cin >> e.u >> e.v >> e.w, e.u--, e.v--;
    sort(rall(es));
    dsu d(n);
    VVI to(n);
    int pre = -1;
    for(auto e: es) {
        if (pre != e.w && d.same(0, n - 1)) break;
        to[e.u].push_back(e.v);
        to[e.v].push_back(e.u);
        d.merge(e.u, e.v);
        pre = e.w;
    }
    cout << pre << ' ';
    VI dist(n, -1);
    queue<int> q;
    auto push = [&](int i, int c) {
        if (dist[i] == -1) {
            dist[i] = c;
            q.push(i);
        }
    };
    push(0, 0);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        int nc = dist[u] + 1;
        for(int v: to[u]) push(v, nc);
    }
    cout << dist[n - 1] << '\n';
}
0