結果

問題 No.1639 最小通信路
ユーザー harurunharurun
提出日時 2021-07-11 21:08:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,996 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 79,252 KB
最終ジャッジ日時 2023-10-17 02:26:55
合計ジャッジ時間 5,849 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,640 KB
testcase_01 AC 61 ms
70,384 KB
testcase_02 AC 133 ms
76,784 KB
testcase_03 AC 145 ms
78,988 KB
testcase_04 AC 124 ms
79,252 KB
testcase_05 AC 98 ms
76,108 KB
testcase_06 AC 106 ms
76,220 KB
testcase_07 AC 62 ms
70,540 KB
testcase_08 AC 114 ms
76,532 KB
testcase_09 AC 73 ms
74,112 KB
testcase_10 AC 92 ms
75,956 KB
testcase_11 AC 119 ms
76,256 KB
testcase_12 AC 98 ms
76,128 KB
testcase_13 AC 134 ms
76,856 KB
testcase_14 AC 60 ms
70,372 KB
testcase_15 AC 91 ms
76,072 KB
testcase_16 AC 112 ms
76,328 KB
testcase_17 AC 121 ms
76,580 KB
testcase_18 AC 78 ms
75,736 KB
testcase_19 AC 102 ms
76,148 KB
testcase_20 AC 118 ms
76,564 KB
testcase_21 AC 49 ms
64,228 KB
testcase_22 AC 100 ms
76,056 KB
testcase_23 AC 109 ms
76,300 KB
testcase_24 AC 96 ms
76,272 KB
testcase_25 AC 93 ms
76,276 KB
testcase_26 AC 82 ms
75,836 KB
testcase_27 AC 63 ms
70,364 KB
testcase_28 AC 61 ms
70,296 KB
testcase_29 AC 118 ms
77,124 KB
testcase_30 AC 120 ms
77,652 KB
testcase_31 AC 81 ms
76,076 KB
testcase_32 AC 117 ms
77,504 KB
testcase_33 AC 81 ms
75,996 KB
testcase_34 AC 112 ms
77,104 KB
testcase_35 AC 134 ms
78,688 KB
testcase_36 AC 111 ms
77,100 KB
testcase_37 AC 112 ms
77,464 KB
testcase_38 AC 67 ms
72,448 KB
testcase_39 AC 96 ms
76,276 KB
testcase_40 AC 87 ms
75,632 KB
testcase_41 AC 69 ms
72,576 KB
testcase_42 AC 126 ms
77,712 KB
testcase_43 AC 85 ms
75,744 KB
testcase_44 AC 66 ms
72,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class INPUT:
  def __init__(self):
    self._l=open(0).read().split()
    self._length=len(self._l)
    self._index=0
    return

  def stream(self,k=1,f=int,f2=False):
    assert(-1<k)
    if self._length==self._index or self._length-self._index<k:
      raise Exception("There is no input!")
    elif f!=str:
      if k==0:
        ret=list(map(f,self._l[self._index:]))
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=f(self._l[self._index])
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[f(self._l[self._index])]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(f(self._l[self._index]))
        self._index+=1
      return ret
    else:
      if k==0:
        ret=list(self._l[self._index:])
        self._index=self._length
        return ret
      if k==1 and not f2:
        ret=self._l[self._index]
        self._index+=1
        return ret
      if k==1 and f2:
        ret=[self._l[self._index]]
        self._index+=1
        return ret
      ret=[]
      for _ in [0]*k:
        ret.append(self._l[self._index])
        self._index+=1
      return ret
pin=INPUT().stream


#pin(number[default:1],f[default:int],f2[default:False])
#if number==0 -> return left all
#listを変数で受け取るとき、必ずlistをTrueにすること。

  
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))

def main():
  N=pin(1)
  d=[[-1]*N for _ in[0]*N]
  for _ in [0]*(N*(N-1)//2):
    a,b,C=pin(3)
    d[a-1][b-1]=C
    d[b-1][a-1]=C
  small=1
  big=pow(10,100)
  for _ in [0]*400:
    mid=(small+big)//2
    uf=dsu(N)
    for i in range(N):
      for j in range(i+1,N):
        if d[i][j]<=mid:
          uf.merge(i,j)
    if uf.size(0)==N:
      big=mid
    else:
      small=mid
  print(big)
  return

main()
0