結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | tamato |
提出日時 | 2020-05-27 11:18:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 289 ms / 2,000 ms |
コード長 | 1,487 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 91,472 KB |
最終ジャッジ日時 | 2024-04-21 05:07:38 |
合計ジャッジ時間 | 5,364 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,736 KB |
testcase_01 | AC | 36 ms
52,480 KB |
testcase_02 | AC | 36 ms
52,608 KB |
testcase_03 | AC | 37 ms
52,096 KB |
testcase_04 | AC | 39 ms
52,736 KB |
testcase_05 | AC | 37 ms
52,384 KB |
testcase_06 | AC | 35 ms
52,096 KB |
testcase_07 | AC | 35 ms
52,096 KB |
testcase_08 | AC | 36 ms
52,140 KB |
testcase_09 | AC | 34 ms
52,096 KB |
testcase_10 | AC | 34 ms
52,352 KB |
testcase_11 | AC | 36 ms
52,608 KB |
testcase_12 | AC | 34 ms
52,864 KB |
testcase_13 | AC | 84 ms
77,664 KB |
testcase_14 | AC | 111 ms
79,672 KB |
testcase_15 | AC | 86 ms
77,684 KB |
testcase_16 | AC | 160 ms
81,764 KB |
testcase_17 | AC | 269 ms
88,392 KB |
testcase_18 | AC | 249 ms
88,904 KB |
testcase_19 | AC | 206 ms
89,028 KB |
testcase_20 | AC | 186 ms
87,732 KB |
testcase_21 | AC | 244 ms
89,056 KB |
testcase_22 | AC | 35 ms
52,264 KB |
testcase_23 | AC | 35 ms
52,096 KB |
testcase_24 | AC | 34 ms
52,608 KB |
testcase_25 | AC | 236 ms
89,344 KB |
testcase_26 | AC | 276 ms
89,800 KB |
testcase_27 | AC | 289 ms
91,472 KB |
testcase_28 | AC | 123 ms
84,408 KB |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.buffer.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return x def unite(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.find_root(x) == self.find_root(y) def size(self, x): return -self.root[self.find_root(x)] N, M, K = map(int, input().split()) E = [] S = 0 for _ in range(M): a, b, c = map(int, input().split()) E.append([a, b, c]) S += c P = 0 for _ in range(K): i = int(input()) - 1 P += E[i][2] E[i][2] = 0 E.sort(key=lambda x: x[2]) UF = UnionFind(N) for a, b, c in E: if not UF.isSameGroup(a, b): UF.unite(a, b) P += c print(S - P) if __name__ == '__main__': main()