結果
| 問題 | No.1639 最小通信路 |
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-08-07 09:21:14 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 91 ms / 2,000 ms |
| + 883µs | |
| コード長 | 786 bytes |
| 記録 | |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 95,468 KB |
| 実行使用メモリ | 84,480 KB |
| 最終ジャッジ日時 | 2026-08-29 14:27:44 |
| 合計ジャッジ時間 | 6,084 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_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