結果
問題 |
No.1639 最小通信路
|
ユーザー |
![]() |
提出日時 | 2021-08-06 22:14:44 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 839 bytes |
コンパイル時間 | 308 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-09-17 02:16:18 |
合計ジャッジ時間 | 3,120 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
N = int(input()) CAB = list() for e in range(N * (N - 1) // 2): A, B, C = map(int, input().split()) CAB.append((C, A - 1, B - 1)) CAB.sort() class DSU: def __init__(self, N: int) -> None: self.par = list(range(N)) self.sz = [1] * N def find(self, x: int) -> int: if self.par[x] != x: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self.sz[x] < self.sz[y]: x, y = y, x self.par[y] = x self.sz[x] += self.sz[y] return True uf = DSU(N) for c, a, b in CAB: if uf.find(a) != uf.find(b): uf.unite(a, b) if uf.sz[uf.find(0)] == N: print(c) exit(0)