結果
| 問題 | No.1639 最小通信路 |
| コンテスト | |
| ユーザー |
wolgnik
|
| 提出日時 | 2021-08-06 22:06:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 972 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 82,192 KB |
| 実行使用メモリ | 71,936 KB |
| 最終ジャッジ日時 | 2024-09-17 02:07:12 |
| 合計ジャッジ時間 | 3,580 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
import sys
input = sys.stdin.readline
N = int(input())
class UnionFind():
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def SameQuery(self, x, y): return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x): return -self.root[self.Find_Root(x)]
uf = UnionFind(N)
res = 0
for _ in range(N * (N - 1) // 2):
u, v, c = map(int, input().split())
if uf.SameQuery(u, v): continue
uf.Unite(u, v)
res = max(res, c)
print(res)
wolgnik