結果
| 問題 |
No.1639 最小通信路
|
| コンテスト | |
| ユーザー |
puzneko
|
| 提出日時 | 2021-12-02 23:54:36 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 824 bytes |
| コンパイル時間 | 235 ms |
| コンパイル使用メモリ | 82,164 KB |
| 実行使用メモリ | 68,900 KB |
| 最終ジャッジ日時 | 2024-07-05 02:17:10 |
| 合計ジャッジ時間 | 3,555 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 43 |
ソースコード
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10000000)
n = int(stdin.readline().rstrip())
par = [i for i in range(n+1)]
rank = [0 for i in range(n+1)]
def root(x):
if par[x] == x:
return x
else:
par[x] = root(par[x])
return par[x]
def unite(x,y):
karix = root(x)
kariy = root(y)
if karix == kariy:
return 0
if rank[karix] < rank[kariy]:
par[karix] = kariy
else:
par[kariy] = karix
if rank[karix] == rank[kariy]:
rank[karix] += 1
def same(x,y):
return root(x) == root(y)
num = 1
for i in range(n*(n-1)//2):
a, b, c = stdin.readline().rstrip().split()
a = int(a)
b = int(b)
if not same(a,b):
num += 1
unite(a,b)
if num == n:
print(c)
exit()
puzneko