結果

問題 No.1639 最小通信路
ユーザー nawawannawawan
提出日時 2021-08-06 22:01:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,231 bytes
コンパイル時間 2,459 ms
コンパイル使用メモリ 174,036 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-17 03:23:33
合計ジャッジ時間 4,002 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 RE -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 AC 2 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 RE -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 RE -
testcase_34 WA -
testcase_35 RE -
testcase_36 WA -
testcase_37 WA -
testcase_38 RE -
testcase_39 WA -
testcase_40 WA -
testcase_41 RE -
testcase_42 WA -
testcase_43 WA -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 1;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) swap(x, y);
        par[y] = x;
        rank[x] += rank[y];
    }

    int size(int x) {
        return rank[root(x)];
    }
};
int main(){
    int N;
    cin >> N;
    vector<int> a(N * (N - 1) / 2), b(N * (N - 1) / 2);
    vector<string> T(N * (N - 1) / 2);
    for(int i = 0; i < N * (N - 1) / 2; i++){
        cin >> a[i] >> b[i] >> T[i];
    }
    int lb = -1, ub = N * (N - 1) / 2;
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        UnionFind U(N);
        for(int i = 0; i <= mid; i++){
            U.unite(a[i], b[i]);
        }
        if(U.size(a[0]) == N) ub = mid;
        else lb = mid;
    }
    cout << T[ub] << endl;
}
0