結果
| 問題 | No.1639 最小通信路 |
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-08-07 09:21:14 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 786 bytes |
| 記録 | |
| コンパイル時間 | 255 ms |
| コンパイル使用メモリ | 85,248 KB |
| 実行使用メモリ | 81,920 KB |
| 最終ジャッジ日時 | 2026-04-06 07:31:53 |
| 合計ジャッジ時間 | 3,251 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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