結果

問題 No.1639 最小通信路
ユーザー harurunharurun
提出日時 2021-06-25 19:54:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,899 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 12,236 KB
実行使用メモリ 12,060 KB
最終ジャッジ日時 2023-10-17 02:23:40
合計ジャッジ時間 3,077 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,252 KB
testcase_01 AC 32 ms
10,252 KB
testcase_02 AC 39 ms
11,840 KB
testcase_03 AC 41 ms
12,060 KB
testcase_04 AC 44 ms
12,060 KB
testcase_05 AC 31 ms
10,448 KB
testcase_06 AC 33 ms
10,772 KB
testcase_07 AC 30 ms
10,252 KB
testcase_08 AC 41 ms
10,944 KB
testcase_09 AC 30 ms
10,272 KB
testcase_10 AC 30 ms
10,384 KB
testcase_11 AC 33 ms
10,828 KB
testcase_12 AC 30 ms
10,404 KB
testcase_13 AC 37 ms
11,056 KB
testcase_14 AC 29 ms
10,252 KB
testcase_15 AC 30 ms
10,388 KB
testcase_16 AC 34 ms
10,852 KB
testcase_17 AC 36 ms
10,896 KB
testcase_18 AC 29 ms
10,268 KB
testcase_19 AC 31 ms
10,708 KB
testcase_20 AC 35 ms
10,956 KB
testcase_21 AC 30 ms
10,252 KB
testcase_22 AC 31 ms
10,420 KB
testcase_23 AC 32 ms
10,768 KB
testcase_24 AC 31 ms
10,400 KB
testcase_25 AC 30 ms
10,380 KB
testcase_26 AC 30 ms
10,276 KB
testcase_27 AC 29 ms
10,252 KB
testcase_28 AC 29 ms
10,252 KB
testcase_29 AC 32 ms
10,772 KB
testcase_30 AC 36 ms
10,912 KB
testcase_31 AC 30 ms
10,372 KB
testcase_32 AC 34 ms
10,816 KB
testcase_33 AC 30 ms
10,284 KB
testcase_34 AC 33 ms
10,780 KB
testcase_35 AC 38 ms
11,104 KB
testcase_36 AC 33 ms
10,764 KB
testcase_37 AC 35 ms
10,832 KB
testcase_38 AC 30 ms
10,252 KB
testcase_39 AC 31 ms
10,384 KB
testcase_40 AC 33 ms
10,268 KB
testcase_41 AC 30 ms
10,284 KB
testcase_42 AC 36 ms
10,888 KB
testcase_43 AC 31 ms
10,292 KB
testcase_44 AC 30 ms
10,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#assert
#C_{i-1}<C_i の検証が抜けてました
class dsu:
  def __init__(self,n):
    assert n>0,"n must be Natural"
    self.n=n
    self.parents=[-1]*n
    return
  
  def find(self,x):
    assert x<self.n,"warning!! this is 0 index"
    if self.parents[x]<0:
      return x
    self.parents[x]=self.find(self.parents[x])
    return self.parents[x]
  
  def merge(self,x,y):
    assert x<self.n and y<self.n,"warning!! this is 0 index"
    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
    return
    
  def size(self,x):
    assert x<self.n,"warning!! this is 0 index"
    return -self.parents[self.find(x)]
    
  def same(self,x,y):
    assert x<self.n and y<self.n,"warning!! this is 0 index"
    return self.find(x)==self.find(y)
  
  def leader(self,x):
    assert x<self.n,"warning!! this is 0 index"
    if self.parents[x]<0:
      return x
    self.parents[x]=self.leader(self.parents[x])
    return self.parents[x]
  
  def groups(self):
    ld=[self.leader(i) for i in range(self.n)]
    res=[[] for _ in range(self.n)]
    for i in range(self.n):
      res[ld[i]].append(i)
    return list(filter(lambda a:a !=[],res))
from sys import stdin
pin=stdin.readline
def main():
  C_SET=set()
  AB_SET=set()
  PRE=0
  MAX_C=pow(10,100)
  N=int(pin())
  assert(2<=N<=100)
  uf=dsu(N)
  FLAG=False
  for _ in[0]*(N*(N-1)//2):
    a,b,s=map(int,pin().rstrip().split())
    #a=int(a)
    #b=int(b)
    assert(1<=a<=N)
    assert(1<=b<=N)
    assert(1<=s<=MAX_C)
    C_SET.add(s)
    AB_SET.add((a,b))
    assert(PRE<s)
    PRE=s
    if FLAG:
      continue
    a-=1
    b-=1
    if uf.same(a,b):
      continue
    uf.merge(a,b)
    if uf.size(0)==N:
      print(s)
      FLAG=True
  assert(2*len(C_SET)==N*(N-1))
  assert(2*len(AB_SET)==N*(N-1))
  return

main()
0