結果
| 問題 | 
                            No.1639 最小通信路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-08-06 22:01:40 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,231 bytes | 
| コンパイル時間 | 1,772 ms | 
| コンパイル使用メモリ | 174,132 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-17 01:59:54 | 
| 合計ジャッジ時間 | 4,767 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge6 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 2 WA * 29 RE * 12 | 
ソースコード
#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;
}