結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-08-06 22:04:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 1,770 ms |
| コンパイル使用メモリ | 173,996 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-17 02:04:17 |
| 合計ジャッジ時間 | 5,028 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 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];
}
UnionFind U(N);
for(int i = 0; i < N * (N - 1) / 2; i++){
U.unite(a[i], b[i]);
if(U.size(a[i]) == N){
cout << T[i] << endl;
break;
}
}
}