結果
問題 | No.1639 最小通信路 |
ユーザー | harurun |
提出日時 | 2021-06-22 02:09:04 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,519 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 82,604 KB |
実行使用メモリ | 70,132 KB |
最終ジャッジ日時 | 2024-09-17 00:52:21 |
合計ジャッジ時間 | 2,774 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
52,792 KB |
testcase_01 | AC | 33 ms
53,640 KB |
testcase_02 | AC | 34 ms
54,528 KB |
testcase_03 | AC | 36 ms
53,812 KB |
testcase_04 | AC | 49 ms
70,132 KB |
testcase_05 | AC | 33 ms
53,244 KB |
testcase_06 | AC | 33 ms
54,236 KB |
testcase_07 | AC | 31 ms
53,324 KB |
testcase_08 | AC | 34 ms
54,360 KB |
testcase_09 | AC | 37 ms
53,488 KB |
testcase_10 | AC | 33 ms
53,904 KB |
testcase_11 | AC | 38 ms
53,216 KB |
testcase_12 | AC | 33 ms
54,136 KB |
testcase_13 | AC | 34 ms
53,668 KB |
testcase_14 | AC | 32 ms
54,012 KB |
testcase_15 | AC | 32 ms
53,120 KB |
testcase_16 | AC | 34 ms
53,276 KB |
testcase_17 | AC | 34 ms
54,076 KB |
testcase_18 | AC | 32 ms
53,136 KB |
testcase_19 | AC | 32 ms
54,376 KB |
testcase_20 | AC | 33 ms
53,464 KB |
testcase_21 | AC | 31 ms
53,384 KB |
testcase_22 | AC | 33 ms
53,016 KB |
testcase_23 | AC | 34 ms
53,420 KB |
testcase_24 | AC | 31 ms
53,008 KB |
testcase_25 | AC | 32 ms
53,816 KB |
testcase_26 | AC | 31 ms
54,040 KB |
testcase_27 | AC | 32 ms
53,616 KB |
testcase_28 | AC | 31 ms
54,056 KB |
testcase_29 | AC | 33 ms
54,112 KB |
testcase_30 | AC | 33 ms
53,076 KB |
testcase_31 | AC | 32 ms
53,616 KB |
testcase_32 | AC | 34 ms
53,784 KB |
testcase_33 | AC | 35 ms
53,872 KB |
testcase_34 | AC | 33 ms
53,568 KB |
testcase_35 | AC | 38 ms
60,452 KB |
testcase_36 | AC | 33 ms
55,488 KB |
testcase_37 | AC | 33 ms
53,380 KB |
testcase_38 | AC | 34 ms
52,932 KB |
testcase_39 | AC | 34 ms
54,156 KB |
testcase_40 | AC | 34 ms
53,136 KB |
testcase_41 | AC | 34 ms
52,656 KB |
testcase_42 | AC | 34 ms
54,264 KB |
testcase_43 | AC | 32 ms
52,880 KB |
testcase_44 | AC | 32 ms
53,268 KB |
ソースコード
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(): N=int(pin()) uf=dsu(N) for _ in[0]*(N*(N-1)//2): a,b,s=pin().rstrip().split() a=int(a) b=int(b) a-=1 b-=1 if uf.same(a,b): continue uf.merge(a,b) if uf.size(0)==N: print(s) return return main()