結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 22:06:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| コード長 | 1,263 bytes |
| コンパイル時間 | 1,731 ms |
| コンパイル使用メモリ | 172,948 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-17 02:06:42 |
| 合計ジャッジ時間 | 3,105 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
#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];
a[i]--;
b[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;
}