結果

問題 No.1639 最小通信路
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-08-06 21:52:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 76,860 KB
最終ジャッジ日時 2023-10-17 03:12:37
合計ジャッジ時間 3,866 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,564 KB
testcase_01 AC 42 ms
53,564 KB
testcase_02 AC 53 ms
66,376 KB
testcase_03 AC 61 ms
70,472 KB
testcase_04 AC 80 ms
76,860 KB
testcase_05 AC 47 ms
62,280 KB
testcase_06 AC 47 ms
62,280 KB
testcase_07 AC 38 ms
53,564 KB
testcase_08 AC 49 ms
64,328 KB
testcase_09 AC 38 ms
53,564 KB
testcase_10 AC 41 ms
55,612 KB
testcase_11 AC 47 ms
64,328 KB
testcase_12 AC 41 ms
55,612 KB
testcase_13 AC 49 ms
64,328 KB
testcase_14 AC 38 ms
53,564 KB
testcase_15 AC 42 ms
55,612 KB
testcase_16 AC 49 ms
64,328 KB
testcase_17 AC 47 ms
64,328 KB
testcase_18 AC 38 ms
53,564 KB
testcase_19 AC 47 ms
62,280 KB
testcase_20 AC 48 ms
64,328 KB
testcase_21 AC 39 ms
53,564 KB
testcase_22 AC 41 ms
55,612 KB
testcase_23 AC 47 ms
62,280 KB
testcase_24 AC 44 ms
55,612 KB
testcase_25 AC 44 ms
55,612 KB
testcase_26 AC 41 ms
53,564 KB
testcase_27 AC 40 ms
53,564 KB
testcase_28 AC 41 ms
53,564 KB
testcase_29 AC 53 ms
64,328 KB
testcase_30 AC 55 ms
66,376 KB
testcase_31 AC 42 ms
55,612 KB
testcase_32 AC 53 ms
64,328 KB
testcase_33 AC 41 ms
53,564 KB
testcase_34 AC 51 ms
64,328 KB
testcase_35 AC 57 ms
68,424 KB
testcase_36 AC 53 ms
64,328 KB
testcase_37 AC 53 ms
64,328 KB
testcase_38 AC 38 ms
53,564 KB
testcase_39 AC 41 ms
55,612 KB
testcase_40 AC 40 ms
53,564 KB
testcase_41 AC 40 ms
53,564 KB
testcase_42 AC 51 ms
66,376 KB
testcase_43 AC 40 ms
53,564 KB
testcase_44 AC 38 ms
53,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from sys import stdin
import heapq

def uf_find(n,p):

    ufl = []

    while p[n] != n:
        ufl.append(n)
        n = p[n]

    for i in ufl:
        p[i] = n

    return n


def uf_union(a,b,p,rank):

    ap = uf_find(a,p)
    bp = uf_find(b,p)

    if ap == bp:
        return True
    else:

        if rank[ap] > rank[bp]:
            p[bp] = ap
        elif rank[ap] < rank[bp]:
            p[ap] = bp
        else:
            p[bp] = ap
            rank[ap] += 1

        return False

N = int(stdin.readline())

CAB = []

for i in range(N*(N-1)//2):

    a,b,c = map(int,stdin.readline().split())
    CAB.append((c,a-1,b-1))

CAB.sort()

p = [i for i in range(N)]
rank = [0] * N
rem = N-1

for i in range(len(CAB)):

    c,a,b = CAB[i]

    if not uf_union(a,b,p,rank):
        rem -= 1

    if rem == 0:
        print (c)
        break
0