結果

問題 No.1639 最小通信路
ユーザー U SU S
提出日時 2021-08-06 22:22:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 2,958 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 77,076 KB
最終ジャッジ日時 2023-10-17 03:46:42
合計ジャッジ時間 4,010 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
61,124 KB
testcase_01 AC 48 ms
61,124 KB
testcase_02 AC 54 ms
63,580 KB
testcase_03 AC 51 ms
63,172 KB
testcase_04 AC 95 ms
77,076 KB
testcase_05 AC 50 ms
61,124 KB
testcase_06 AC 51 ms
63,172 KB
testcase_07 AC 48 ms
61,124 KB
testcase_08 AC 52 ms
63,172 KB
testcase_09 AC 48 ms
61,124 KB
testcase_10 AC 48 ms
61,124 KB
testcase_11 AC 50 ms
61,124 KB
testcase_12 AC 49 ms
61,124 KB
testcase_13 AC 51 ms
63,172 KB
testcase_14 AC 47 ms
61,124 KB
testcase_15 AC 49 ms
61,124 KB
testcase_16 AC 51 ms
63,172 KB
testcase_17 AC 51 ms
63,172 KB
testcase_18 AC 48 ms
61,124 KB
testcase_19 AC 50 ms
61,124 KB
testcase_20 AC 54 ms
63,580 KB
testcase_21 AC 48 ms
61,124 KB
testcase_22 AC 49 ms
61,124 KB
testcase_23 AC 49 ms
61,124 KB
testcase_24 AC 48 ms
61,124 KB
testcase_25 AC 48 ms
61,124 KB
testcase_26 AC 48 ms
61,124 KB
testcase_27 AC 47 ms
61,124 KB
testcase_28 AC 47 ms
61,124 KB
testcase_29 AC 48 ms
61,124 KB
testcase_30 AC 51 ms
63,172 KB
testcase_31 AC 48 ms
61,124 KB
testcase_32 AC 49 ms
61,124 KB
testcase_33 AC 48 ms
61,124 KB
testcase_34 AC 50 ms
63,172 KB
testcase_35 AC 56 ms
65,776 KB
testcase_36 AC 52 ms
63,172 KB
testcase_37 AC 50 ms
63,172 KB
testcase_38 AC 47 ms
61,124 KB
testcase_39 AC 48 ms
61,124 KB
testcase_40 AC 47 ms
61,124 KB
testcase_41 AC 48 ms
61,124 KB
testcase_42 AC 50 ms
63,172 KB
testcase_43 AC 47 ms
61,124 KB
testcase_44 AC 47 ms
61,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import sys
# #sys.setrecursionlimit(1000000)
# input = sys.stdin.readline
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque
import itertools
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1
inf = int(1e30)
mod = int(1e9+7)
class UnionFind():
    def __init__(self, n):
        # uf.parentsで各ノードの親をリストで返す
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        # uf.find(x)で処理を行う
        # 要素xが属するグループの根を返す(経路圧縮)
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        # uf.union(x,y)で処理を行う
        # 要素xが属するグループと要素yが属するグループを併合する
        # 小さい部分木を大きい部分木にくっつける
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        # uf.size(x)で処理を行う
        # 要素xが属するグループの要素数を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):
        # uf.same(x,y)で処理を行う
        # 要素x,yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def members(self, x):
        # uf.members(x)で処理を行う
        # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        # uf.roots()で処理を行う
        # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        # uf.group_count()で処理を行う
        # グループの数を返す
        return len(self.roots())

    def all_group_members(self):
        # all_group_members()で処理を行う
        # 極力使わないこと
        # {ルート要素:[グループに属する要素のリスト]}をdict型で返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        # ルート要素:[グループに属する要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n = int(input())
uf = UnionFind(n)
tar = -1
for i in range(n*(n-1)//2):
    a,b,c = mp()
    a -= 1
    b -= 1
    if i == 0:tar = a
    uf.union(a,b)
    if uf.size(tar) == n:
        print(c)
        exit()

0