結果
問題 |
No.1639 最小通信路
|
ユーザー |
![]() |
提出日時 | 2021-06-24 19:00:29 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,813 bytes |
コンパイル時間 | 204 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 13,184 KB |
最終ジャッジ日時 | 2024-09-17 00:53:49 |
合計ジャッジ時間 | 2,417 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
#assert 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() 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=pin().rstrip().split() a=int(a) b=int(b) assert(1<=a<=N) assert(1<=b<=N) assert(1<=int(s)<=MAX_C) C_SET.add(s) AB_SET.add((a,b)) 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()