結果

問題 No.1639 最小通信路
ユーザー moharan627moharan627
提出日時 2021-08-06 22:19:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 2,156 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 77,536 KB
最終ジャッジ日時 2023-10-17 03:43:10
合計ジャッジ時間 4,768 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,576 KB
testcase_01 AC 38 ms
55,576 KB
testcase_02 AC 105 ms
72,896 KB
testcase_03 AC 71 ms
77,536 KB
testcase_04 AC 71 ms
77,528 KB
testcase_05 AC 59 ms
68,804 KB
testcase_06 AC 54 ms
68,796 KB
testcase_07 AC 36 ms
55,584 KB
testcase_08 AC 52 ms
70,844 KB
testcase_09 AC 39 ms
55,584 KB
testcase_10 AC 43 ms
63,292 KB
testcase_11 AC 55 ms
70,852 KB
testcase_12 AC 45 ms
63,292 KB
testcase_13 AC 56 ms
70,852 KB
testcase_14 AC 38 ms
55,584 KB
testcase_15 AC 42 ms
63,292 KB
testcase_16 AC 54 ms
70,852 KB
testcase_17 AC 55 ms
70,844 KB
testcase_18 AC 39 ms
55,584 KB
testcase_19 AC 52 ms
68,796 KB
testcase_20 AC 53 ms
70,844 KB
testcase_21 AC 37 ms
55,584 KB
testcase_22 AC 45 ms
63,296 KB
testcase_23 AC 56 ms
68,804 KB
testcase_24 AC 46 ms
63,296 KB
testcase_25 AC 43 ms
61,000 KB
testcase_26 AC 38 ms
55,584 KB
testcase_27 AC 37 ms
55,584 KB
testcase_28 AC 37 ms
55,584 KB
testcase_29 AC 57 ms
70,720 KB
testcase_30 AC 59 ms
72,772 KB
testcase_31 AC 40 ms
57,632 KB
testcase_32 AC 59 ms
70,724 KB
testcase_33 AC 40 ms
55,584 KB
testcase_34 AC 58 ms
70,724 KB
testcase_35 AC 62 ms
74,096 KB
testcase_36 AC 56 ms
70,720 KB
testcase_37 AC 59 ms
70,720 KB
testcase_38 AC 38 ms
55,584 KB
testcase_39 AC 44 ms
61,244 KB
testcase_40 AC 37 ms
55,584 KB
testcase_41 AC 38 ms
55,584 KB
testcase_42 AC 57 ms
72,768 KB
testcase_43 AC 41 ms
55,584 KB
testcase_44 AC 38 ms
55,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
INF = float('inf')
#10**20,2**63,float('inf')
MOD = 10**9 + 7
MOD2 = 998244353
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, 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):
        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):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())

def solve():
    def II(): return int(sys.stdin.readline())
    def LI(): return list(map(int, sys.stdin.readline().split()))
    def LC(): return list(input())
    def IC(): return [int(c) for c in input()]
    def MI(): return map(int, sys.stdin.readline().split())
    N = II()
    Edge = defaultdict(lambda:[])
    for _ in range(N*(N-1)//2):
        A,B,C= MI()
        Edge[C].append((A,B))
    uf = UnionFind(N+1)
    Weight = list(Edge.keys())
    Ans = -INF
    for w in Weight:
        for s,t in Edge[w]:
            if(uf.same(s,t)):
                continue
            else:
                uf.union(s,t)
                Ans = max(Ans,w)
    print(Ans)
    return
solve()
#sys.setrecursionlimit(10 ** 6)#再帰関数ではコメントにしないこと!!
0