結果

問題 No.1473 おでぶなおばけさん
ユーザー rogi52rogi52
提出日時 2022-10-02 18:57:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 212,996 KB
実行使用メモリ 10,284 KB
最終ジャッジ日時 2023-08-26 16:38:43
合計ジャッジ時間 6,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 85 ms
9,552 KB
testcase_03 AC 66 ms
8,248 KB
testcase_04 AC 46 ms
6,584 KB
testcase_05 AC 17 ms
4,380 KB
testcase_06 AC 72 ms
8,124 KB
testcase_07 AC 90 ms
10,268 KB
testcase_08 AC 91 ms
10,284 KB
testcase_09 AC 93 ms
10,208 KB
testcase_10 AC 28 ms
4,376 KB
testcase_11 AC 26 ms
4,420 KB
testcase_12 AC 28 ms
4,380 KB
testcase_13 AC 18 ms
4,380 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 26 ms
4,380 KB
testcase_16 AC 28 ms
4,516 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 5 ms
4,376 KB
testcase_19 AC 26 ms
4,556 KB
testcase_20 AC 43 ms
7,520 KB
testcase_21 AC 44 ms
6,120 KB
testcase_22 AC 40 ms
8,720 KB
testcase_23 AC 34 ms
8,344 KB
testcase_24 AC 33 ms
8,000 KB
testcase_25 AC 89 ms
8,420 KB
testcase_26 AC 96 ms
8,396 KB
testcase_27 AC 29 ms
4,684 KB
testcase_28 AC 70 ms
9,992 KB
testcase_29 AC 45 ms
5,992 KB
testcase_30 AC 60 ms
6,748 KB
testcase_31 AC 71 ms
9,872 KB
testcase_32 AC 50 ms
8,108 KB
testcase_33 AC 43 ms
7,328 KB
testcase_34 AC 25 ms
5,324 KB
testcase_35 AC 23 ms
4,800 KB
testcase_36 AC 44 ms
6,540 KB
testcase_37 AC 51 ms
8,024 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 27 ms
4,384 KB
testcase_40 AC 28 ms
4,420 KB
testcase_41 AC 25 ms
4,400 KB
testcase_42 AC 26 ms
4,380 KB
testcase_43 AC 35 ms
7,544 KB
testcase_44 AC 35 ms
7,480 KB
testcase_45 AC 35 ms
7,464 KB
testcase_46 AC 73 ms
7,172 KB
testcase_47 AC 94 ms
8,244 KB
testcase_48 AC 82 ms
8,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

class union_find {
  public:
    union_find(int n) : data(n, -1) {}
    int unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            if(size(x) < size(y)) swap(x, y);
            data[x] += data[y];
            return data[y] = x;
        }
        return -1;
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    bool same(int x, int y) { return root(x) == root(y); }

  private:
    vector<int> data;
};

vector< int > bfs(vector<vector<int>> &graph, int s) {
    int INF = numeric_limits<int>::max();
    vector<int> dist(graph.size(), INF);
    queue<int> q;
    dist[s] = 0, q.push(s);
    while(!q.empty()){
        int u = q.front(); q.pop();
        for(int v : graph[u]) if(dist[v] > dist[u] + 1)
            dist[v] = dist[u] + 1, q.push(v);
    }
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n,m; cin >> n >> m;
    vector<tuple<int,int,int>> es(m);
    for(auto &[s, t, d] : es) {
        cin >> s >> t >> d; s--; t--;
    }

    int w_max = [&]() {
        int ok = 0, ng = 1e9+1;
        while(ng - ok > 1) {
            int mid = (ok + ng) / 2;
            ([&](int w) {
                union_find uf(n);
                for(auto [s, t, d] : es) if(w <= d) uf.unite(s, t);
                return uf.same(0, n - 1);
            }(mid) ? ok : ng) = mid;
        }
        return ok;
    }();

    vector<vector<int>> G(n);
    for(auto [s, t, d] : es) if(w_max <= d) {
        G[s].push_back(t);
        G[t].push_back(s);
    }

    cout << w_max << " " << bfs(G, 0)[n - 1] << endl;
}
0