結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | tktk_snsn |
提出日時 | 2021-01-05 23:35:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 609 ms / 2,000 ms |
コード長 | 1,312 bytes |
コンパイル時間 | 291 ms |
コンパイル使用メモリ | 86,780 KB |
実行使用メモリ | 95,980 KB |
最終ジャッジ日時 | 2023-08-06 05:37:20 |
合計ジャッジ時間 | 9,575 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
71,316 KB |
testcase_01 | AC | 72 ms
71,396 KB |
testcase_02 | AC | 70 ms
71,172 KB |
testcase_03 | AC | 72 ms
71,352 KB |
testcase_04 | AC | 71 ms
71,148 KB |
testcase_05 | AC | 74 ms
71,260 KB |
testcase_06 | AC | 72 ms
71,368 KB |
testcase_07 | AC | 72 ms
71,264 KB |
testcase_08 | AC | 72 ms
71,100 KB |
testcase_09 | AC | 73 ms
71,256 KB |
testcase_10 | AC | 73 ms
71,188 KB |
testcase_11 | AC | 73 ms
71,328 KB |
testcase_12 | AC | 72 ms
71,100 KB |
testcase_13 | AC | 129 ms
79,420 KB |
testcase_14 | AC | 213 ms
82,184 KB |
testcase_15 | AC | 146 ms
80,376 KB |
testcase_16 | AC | 290 ms
84,640 KB |
testcase_17 | AC | 515 ms
93,692 KB |
testcase_18 | AC | 609 ms
95,596 KB |
testcase_19 | AC | 522 ms
95,588 KB |
testcase_20 | AC | 430 ms
93,000 KB |
testcase_21 | AC | 605 ms
95,320 KB |
testcase_22 | AC | 71 ms
71,328 KB |
testcase_23 | AC | 71 ms
71,176 KB |
testcase_24 | AC | 76 ms
71,176 KB |
testcase_25 | AC | 402 ms
90,840 KB |
testcase_26 | AC | 542 ms
95,212 KB |
testcase_27 | AC | 599 ms
95,980 KB |
testcase_28 | AC | 292 ms
88,040 KB |
ソースコード
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) class UF_tree: def __init__(self, n): self.root = [-1] * (n + 1) self.rank = [0] * (n + 1) def find(self, x): if self.root[x] < 0: return x self.root[x] = self.find(self.root[x]) return self.root[x] def isSame(self, x, y): return self.find(x) == self.find(y) def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.rank[x] < self.rank[y]: self.root[y] += self.root[x] self.root[x] = y else: self.root[x] += self.root[y] self.root[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 return True def size(self, x): return -self.root[self.find(x)] N, M, K = map(int, input().split()) uf = UF_tree(N) edge = [-1] * M for i in range(M): a, b, c = map(int, input().split()) edge[i] = (c, a-1, b-1, i) used = [0] * M for _ in range(K): x = int(input()) - 1 _, a, b, _ = edge[x] uf.unite(a, b) used[x] = 1 edge.sort() ans = 0 for c, a, b, i in edge: if used[i]: continue if uf.unite(a, b): continue ans += c print(ans)