結果
| 問題 | 
                            No.1639 最小通信路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sotanishy
                         | 
                    
| 提出日時 | 2021-08-06 21:48:56 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 85 ms / 2,000 ms | 
| コード長 | 988 bytes | 
| コンパイル時間 | 242 ms | 
| コンパイル使用メモリ | 82,304 KB | 
| 実行使用メモリ | 76,672 KB | 
| 最終ジャッジ日時 | 2024-09-17 01:42:36 | 
| 合計ジャッジ時間 | 4,055 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 43 | 
ソースコード
import sys
input = sys.stdin.readline
class UnionFind:
    def __init__(self, N):
        self.par = [-1] * N
    def find(self, x):
        r = x
        while self.par[r] >= 0:
            r = self.par[r]
        while x != r:
            tmp = self.par[x]
            self.par[x] = r
            x = tmp
        return r
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def size(self, x):
        return -self.par[self.find(x)]
N = int(input())
edges = []
for _ in range(N*(N-1)//2):
    a, b, C = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b, C))
uf = UnionFind(N)
ans = 0
for u, v, weight in edges:
    if not uf.same(u, v):
        uf.unite(u, v)
        ans = max(ans, weight)
print(ans)
            
            
            
        
            
sotanishy