結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | takeya_okino |
提出日時 | 2021-09-25 12:51:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 610 ms / 2,000 ms |
コード長 | 1,874 bytes |
コンパイル時間 | 181 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 95,988 KB |
最終ジャッジ日時 | 2024-07-05 12:04:07 |
合計ジャッジ時間 | 8,451 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
55,312 KB |
testcase_01 | AC | 41 ms
54,196 KB |
testcase_02 | AC | 41 ms
55,720 KB |
testcase_03 | AC | 41 ms
55,440 KB |
testcase_04 | AC | 42 ms
55,864 KB |
testcase_05 | AC | 41 ms
54,864 KB |
testcase_06 | AC | 41 ms
55,260 KB |
testcase_07 | AC | 41 ms
54,768 KB |
testcase_08 | AC | 41 ms
55,372 KB |
testcase_09 | AC | 42 ms
54,336 KB |
testcase_10 | AC | 42 ms
54,432 KB |
testcase_11 | AC | 43 ms
55,252 KB |
testcase_12 | AC | 41 ms
54,684 KB |
testcase_13 | AC | 145 ms
79,240 KB |
testcase_14 | AC | 216 ms
81,204 KB |
testcase_15 | AC | 163 ms
78,900 KB |
testcase_16 | AC | 321 ms
85,220 KB |
testcase_17 | AC | 515 ms
94,956 KB |
testcase_18 | AC | 598 ms
95,628 KB |
testcase_19 | AC | 610 ms
95,584 KB |
testcase_20 | AC | 542 ms
92,688 KB |
testcase_21 | AC | 578 ms
94,848 KB |
testcase_22 | AC | 42 ms
55,628 KB |
testcase_23 | AC | 43 ms
54,584 KB |
testcase_24 | AC | 40 ms
55,708 KB |
testcase_25 | AC | 403 ms
95,540 KB |
testcase_26 | AC | 556 ms
95,988 KB |
testcase_27 | AC | 526 ms
95,720 KB |
testcase_28 | AC | 426 ms
89,044 KB |
ソースコード
n, m, k = map(int, input().split()) A=[] sum = 0 a = [0 for i in range(m)] b = [0 for i in range(m)] c = [0 for i in range(m)] d = [0 for i in range(m)] for i in range(m): a[i], b[i], c[i] = map(int, input().split()) sum += c[i] for i in range(k): e = int(input()) d[e - 1] = 1 for i in range(m): A.append([c[i], a[i] - 1, b[i] - 1, d[i]]) A.sort() from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): 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 def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) t = 0 uf = UnionFind(n) for [c, a, b, d] in A: if d == 1: t += c uf.union(a,b) for [c, a, b, d] in A: if d == 0: if not uf.same(a,b): t += c uf.union(a,b) print(sum - t)