結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-08-07 09:21:14 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 72 ms / 2,000 ms |
| コード長 | 786 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 82,452 KB |
| 実行使用メモリ | 77,288 KB |
| 最終ジャッジ日時 | 2024-09-17 13:17:11 |
| 合計ジャッジ時間 | 4,193 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
class UnionFind():
def __init__(self,n):
self.n = n
self.arr = [-1] * n
def find(self,x):
if self.arr[x] < 0:
return x
self.arr[x] = self.find(self.arr[x])
return self.arr[x]
def union(self,x,y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.arr[y] < self.arr[x]:
x,y = y,x
self.arr[x] += self.arr[y]
self.arr[y] = x
n = int(input())
l = []
for i in range(n*(n-1)//2):
a,b,c = map(int,input().split())
l.append((c,a-1,b-1))
l.sort()
uf = UnionFind(n)
cnt = 0
ans = 0
for i in range(n*(n-1)//2):
c,a,b = l[i]
if uf.find(a) != uf.find(b):
cnt += 1
uf.union(a,b)
ans = c
print(ans)
SidewaysOwl