結果

問題 No.1473 おでぶなおばけさん
ユーザー milanis48663220milanis48663220
提出日時 2021-04-09 21:45:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,218 bytes
コンパイル時間 1,037 ms
コンパイル使用メモリ 106,096 KB
実行使用メモリ 10,248 KB
最終ジャッジ日時 2023-09-07 10:40:22
合計ジャッジ時間 5,786 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 103 ms
9,668 KB
testcase_03 AC 79 ms
8,084 KB
testcase_04 AC 54 ms
6,784 KB
testcase_05 AC 21 ms
4,376 KB
testcase_06 AC 87 ms
8,000 KB
testcase_07 AC 110 ms
10,248 KB
testcase_08 AC 108 ms
10,088 KB
testcase_09 AC 104 ms
10,060 KB
testcase_10 AC 30 ms
4,444 KB
testcase_11 AC 31 ms
4,532 KB
testcase_12 AC 31 ms
4,380 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 29 ms
4,380 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 29 ms
4,628 KB
testcase_20 AC 48 ms
7,592 KB
testcase_21 AC 51 ms
6,012 KB
testcase_22 AC 44 ms
8,792 KB
testcase_23 AC 37 ms
8,348 KB
testcase_24 AC 36 ms
7,844 KB
testcase_25 AC 97 ms
8,404 KB
testcase_26 AC 104 ms
8,276 KB
testcase_27 AC 31 ms
4,576 KB
testcase_28 AC 82 ms
9,940 KB
testcase_29 AC 50 ms
6,232 KB
testcase_30 AC 64 ms
6,792 KB
testcase_31 AC 80 ms
9,868 KB
testcase_32 AC 56 ms
8,036 KB
testcase_33 AC 51 ms
7,276 KB
testcase_34 AC 30 ms
5,312 KB
testcase_35 AC 27 ms
4,876 KB
testcase_36 AC 53 ms
6,252 KB
testcase_37 AC 60 ms
7,972 KB
testcase_38 AC 13 ms
4,376 KB
testcase_39 AC 30 ms
4,436 KB
testcase_40 AC 30 ms
4,384 KB
testcase_41 AC 28 ms
4,380 KB
testcase_42 AC 29 ms
4,380 KB
testcase_43 AC 41 ms
7,512 KB
testcase_44 AC 41 ms
7,480 KB
testcase_45 AC 41 ms
7,648 KB
testcase_46 AC 88 ms
7,336 KB
testcase_47 AC 109 ms
8,300 KB
testcase_48 AC 93 ms
8,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;


struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
        if (data[y] < data[x]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<int> s(m), t(m), d(m);
    for(int i = 0;i < m; i++){
        cin >> s[i] >> t[i] >> d[i];
        s[i]--; t[i]--;
    }
    int l = 1, r = (1e9)+1000;
    while(r-l > 1){
        UnionFind uf(n);
        int c = (r+l)/2;
        for(int i = 0; i < m; i++){
            if(d[i] >= c) uf.unionSet(s[i], t[i]);
        }
        if(uf.findSet(0, n-1)) l = c;
        else r = c;
    }

    vector<vector<int>> g(n);
    for(int i = 0; i < m; i++){
        if(d[i] >= l) {
            g[s[i]].push_back(t[i]);
            g[t[i]].push_back(s[i]);
        }
    }

    vector<bool> used(n, false);
    vector<int> dist(n);
    queue<int> que;
    que.push(0);
    dist[0] = 0;
    used[0] = true;
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(int to : g[v]){
            if(!used[to]){
                used[to] = true;
                dist[to] = dist[v]+1;
                que.push(to);
            }
        }
    }
    cout << l << ' ' << dist[n-1] << endl;
}
0