結果

問題 No.1639 最小通信路
ユーザー wolgnikwolgnik
提出日時 2021-08-06 22:06:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 972 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 72,592 KB
最終ジャッジ日時 2023-10-17 03:29:57
合計ジャッジ時間 5,330 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,476 KB
testcase_01 AC 37 ms
53,476 KB
testcase_02 AC 50 ms
66,440 KB
testcase_03 AC 58 ms
70,532 KB
testcase_04 AC 59 ms
72,592 KB
testcase_05 AC 49 ms
64,392 KB
testcase_06 AC 51 ms
64,392 KB
testcase_07 AC 37 ms
53,476 KB
testcase_08 AC 50 ms
64,384 KB
testcase_09 AC 39 ms
53,476 KB
testcase_10 AC 43 ms
61,244 KB
testcase_11 AC 84 ms
64,384 KB
testcase_12 AC 97 ms
61,244 KB
testcase_13 AC 107 ms
66,440 KB
testcase_14 AC 74 ms
53,476 KB
testcase_15 AC 88 ms
61,244 KB
testcase_16 AC 101 ms
64,384 KB
testcase_17 AC 102 ms
64,384 KB
testcase_18 AC 79 ms
53,476 KB
testcase_19 AC 105 ms
64,392 KB
testcase_20 AC 104 ms
66,440 KB
testcase_21 AC 76 ms
53,476 KB
testcase_22 AC 94 ms
61,240 KB
testcase_23 AC 100 ms
64,384 KB
testcase_24 AC 87 ms
61,240 KB
testcase_25 AC 78 ms
58,948 KB
testcase_26 AC 39 ms
53,476 KB
testcase_27 AC 38 ms
53,476 KB
testcase_28 AC 37 ms
53,476 KB
testcase_29 AC 76 ms
66,448 KB
testcase_30 AC 114 ms
68,496 KB
testcase_31 AC 82 ms
53,476 KB
testcase_32 AC 89 ms
66,448 KB
testcase_33 AC 78 ms
53,476 KB
testcase_34 AC 105 ms
66,436 KB
testcase_35 AC 113 ms
68,484 KB
testcase_36 AC 105 ms
66,448 KB
testcase_37 AC 109 ms
66,436 KB
testcase_38 AC 79 ms
53,476 KB
testcase_39 AC 72 ms
59,192 KB
testcase_40 AC 45 ms
53,476 KB
testcase_41 AC 39 ms
53,476 KB
testcase_42 AC 54 ms
66,448 KB
testcase_43 AC 39 ms
53,476 KB
testcase_44 AC 37 ms
53,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1] * (n + 1)
    self.rnk = [0] * (n + 1)
  def Find_Root(self, x):
    if self.root[x] < 0:
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if x == y:
      return 
    elif self.rnk[x] > self.rnk[y]:
      self.root[x] += self.root[y]
      self.root[y] = x
    else:
      self.root[y] += self.root[x]
      self.root[x] = y
      if self.rnk[x] == self.rnk[y]:
        self.rnk[y] += 1
  def SameQuery(self, x, y): return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): return -self.root[self.Find_Root(x)]

uf = UnionFind(N)
res = 0
for _ in range(N * (N - 1) // 2):
  u, v, c = map(int, input().split())
  if uf.SameQuery(u, v): continue
  uf.Unite(u, v)
  res = max(res, c)
print(res)
0