結果
問題 | No.1639 最小通信路 |
ユーザー | hiragn |
提出日時 | 2022-12-04 02:44:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 2,188 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-10-11 04:43:52 |
合計ジャッジ時間 | 3,244 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
11,008 KB |
testcase_01 | AC | 34 ms
11,008 KB |
testcase_02 | AC | 33 ms
10,880 KB |
testcase_03 | AC | 32 ms
11,008 KB |
testcase_04 | AC | 54 ms
10,880 KB |
testcase_05 | AC | 32 ms
11,008 KB |
testcase_06 | AC | 32 ms
11,008 KB |
testcase_07 | AC | 31 ms
11,008 KB |
testcase_08 | AC | 32 ms
11,008 KB |
testcase_09 | AC | 32 ms
10,880 KB |
testcase_10 | AC | 32 ms
11,008 KB |
testcase_11 | AC | 33 ms
11,008 KB |
testcase_12 | AC | 31 ms
11,136 KB |
testcase_13 | AC | 32 ms
11,008 KB |
testcase_14 | AC | 32 ms
11,008 KB |
testcase_15 | AC | 31 ms
11,136 KB |
testcase_16 | AC | 32 ms
11,008 KB |
testcase_17 | AC | 32 ms
11,008 KB |
testcase_18 | AC | 31 ms
10,880 KB |
testcase_19 | AC | 32 ms
11,008 KB |
testcase_20 | AC | 33 ms
10,880 KB |
testcase_21 | AC | 31 ms
10,880 KB |
testcase_22 | AC | 31 ms
11,008 KB |
testcase_23 | AC | 32 ms
10,880 KB |
testcase_24 | AC | 32 ms
11,008 KB |
testcase_25 | AC | 32 ms
11,136 KB |
testcase_26 | AC | 31 ms
11,008 KB |
testcase_27 | AC | 31 ms
11,008 KB |
testcase_28 | AC | 30 ms
10,880 KB |
testcase_29 | AC | 31 ms
11,008 KB |
testcase_30 | AC | 32 ms
11,008 KB |
testcase_31 | AC | 31 ms
10,880 KB |
testcase_32 | AC | 32 ms
11,008 KB |
testcase_33 | AC | 31 ms
11,008 KB |
testcase_34 | AC | 32 ms
11,008 KB |
testcase_35 | AC | 33 ms
11,008 KB |
testcase_36 | AC | 32 ms
11,008 KB |
testcase_37 | AC | 31 ms
11,136 KB |
testcase_38 | AC | 32 ms
11,008 KB |
testcase_39 | AC | 31 ms
11,008 KB |
testcase_40 | AC | 31 ms
10,880 KB |
testcase_41 | AC | 31 ms
11,136 KB |
testcase_42 | AC | 33 ms
11,008 KB |
testcase_43 | AC | 31 ms
11,008 KB |
testcase_44 | AC | 32 ms
11,008 KB |
ソースコード
class UnionFind: n = 1 parent_or_size = [-1 for i in range(n)] def __init__(self, n0): self.n = n0 self.parent_or_size = [-1 for _ in range(n0)] def merge(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) x = self.leader(a) y = self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a, b): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) assert 0 <= b < self.n, "0<=b<n,b={0},n={1}".format(b, self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) if self.parent_or_size[a] < 0: return a self.parent_or_size[a] = self.leader(self.parent_or_size[a]) return self.parent_or_size[a] def size(self, a): assert 0 <= a < self.n, "0<=a<n,a={0},n={1}".format(a, self.n) return -self.parent_or_size[self.leader(a)] def groups(self): leader_buf = [0 for _ in range(self.n)] group_size = [0 for _ in range(self.n)] for i in range(self.n): leader_buf[i] = self.leader(i) group_size[leader_buf[i]] += 1 result = [[] for _ in range(self.n)] for i in range(self.n): result[leader_buf[i]].append(i) result2 = [] for i in range(self.n): if len(result[i]) > 0: result2.append(result[i]) return result2 def main(): n = int(input()) uf = UnionFind(n) for _ in range(n * (n - 1) // 2): a, b, c = map(int, input().split()) a -= 1 b -= 1 if uf.same(a, b): # cは降順なので初回につなぐ continue uf.merge(a, b) if uf.size(0) == n: # 全部つながったら終わり。 exit(print(c)) if __name__ == "__main__": main()