結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-08-06 23:40:36 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 2,000 ms |
| コード長 | 1,144 bytes |
| コンパイル時間 | 171 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 12,672 KB |
| 最終ジャッジ日時 | 2024-09-17 04:15:35 |
| 合計ジャッジ時間 | 3,007 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
class UF_tree:
def __init__(self, n):
self.root = [-1] * (n + 1)
self.rank = [0] * (n + 1)
def find(self, x):
if self.root[x] < 0:
return x
self.root[x] = self.find(self.root[x])
return self.root[x]
def isSame(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return False
if self.rank[x] < self.rank[y]:
self.root[y] += self.root[x]
self.root[x] = y
else:
self.root[x] += self.root[y]
self.root[y] = x
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
return True
def size(self, x):
return -self.root[self.find(x)]
N = int(input())
U = N * (N - 1) // 2
abc = [input().rstrip().split() for _ in range(U)]
uf = UF_tree(N)
ans = -1
for a, b, c in abc:
a = int(a) - 1
b = int(b) - 1
if uf.unite(a, b):
ans = c
if uf.size(0) == N:
break
print(ans)
tktk_snsn