結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | takeya_okino |
提出日時 | 2021-09-25 12:51:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 681 ms / 2,000 ms |
コード長 | 1,874 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 87,048 KB |
実行使用メモリ | 98,308 KB |
最終ジャッジ日時 | 2023-09-18 23:00:04 |
合計ジャッジ時間 | 10,922 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
71,600 KB |
testcase_01 | AC | 89 ms
71,636 KB |
testcase_02 | AC | 91 ms
71,524 KB |
testcase_03 | AC | 90 ms
71,584 KB |
testcase_04 | AC | 90 ms
71,632 KB |
testcase_05 | AC | 88 ms
71,384 KB |
testcase_06 | AC | 88 ms
71,564 KB |
testcase_07 | AC | 89 ms
71,644 KB |
testcase_08 | AC | 92 ms
71,704 KB |
testcase_09 | AC | 91 ms
71,704 KB |
testcase_10 | AC | 91 ms
71,828 KB |
testcase_11 | AC | 91 ms
71,528 KB |
testcase_12 | AC | 92 ms
71,616 KB |
testcase_13 | AC | 187 ms
80,988 KB |
testcase_14 | AC | 257 ms
83,028 KB |
testcase_15 | AC | 201 ms
81,068 KB |
testcase_16 | AC | 357 ms
85,840 KB |
testcase_17 | AC | 600 ms
97,156 KB |
testcase_18 | AC | 679 ms
98,308 KB |
testcase_19 | AC | 681 ms
97,740 KB |
testcase_20 | AC | 617 ms
97,444 KB |
testcase_21 | AC | 624 ms
97,160 KB |
testcase_22 | AC | 93 ms
71,536 KB |
testcase_23 | AC | 88 ms
71,396 KB |
testcase_24 | AC | 91 ms
71,692 KB |
testcase_25 | AC | 457 ms
96,752 KB |
testcase_26 | AC | 641 ms
96,904 KB |
testcase_27 | AC | 606 ms
96,756 KB |
testcase_28 | AC | 488 ms
90,656 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)