結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | shinichi |
提出日時 | 2023-01-29 02:35:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 628 ms / 2,000 ms |
コード長 | 1,078 bytes |
コンパイル時間 | 414 ms |
コンパイル使用メモリ | 87,052 KB |
実行使用メモリ | 118,852 KB |
最終ジャッジ日時 | 2023-09-11 12:07:53 |
合計ジャッジ時間 | 11,060 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
70,988 KB |
testcase_01 | AC | 77 ms
70,828 KB |
testcase_02 | AC | 76 ms
71,276 KB |
testcase_03 | AC | 74 ms
70,972 KB |
testcase_04 | AC | 76 ms
70,832 KB |
testcase_05 | AC | 75 ms
70,832 KB |
testcase_06 | AC | 76 ms
70,832 KB |
testcase_07 | AC | 75 ms
71,048 KB |
testcase_08 | AC | 76 ms
71,008 KB |
testcase_09 | AC | 79 ms
70,832 KB |
testcase_10 | AC | 78 ms
71,312 KB |
testcase_11 | AC | 77 ms
70,992 KB |
testcase_12 | AC | 76 ms
70,724 KB |
testcase_13 | AC | 183 ms
81,232 KB |
testcase_14 | AC | 245 ms
84,640 KB |
testcase_15 | AC | 180 ms
81,560 KB |
testcase_16 | AC | 344 ms
91,432 KB |
testcase_17 | AC | 527 ms
104,028 KB |
testcase_18 | AC | 628 ms
112,084 KB |
testcase_19 | AC | 611 ms
118,852 KB |
testcase_20 | AC | 504 ms
114,820 KB |
testcase_21 | AC | 619 ms
114,532 KB |
testcase_22 | AC | 78 ms
70,928 KB |
testcase_23 | AC | 76 ms
71,188 KB |
testcase_24 | AC | 76 ms
71,052 KB |
testcase_25 | AC | 362 ms
100,620 KB |
testcase_26 | AC | 563 ms
111,356 KB |
testcase_27 | AC | 607 ms
112,048 KB |
testcase_28 | AC | 386 ms
106,828 KB |
ソースコード
import heapq class UnionFind: def __init__(self, size): self.parent = [-1] * size def union(self, x, y): x, y = self.root(x), self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x return True def root(self, x): if self.parent[x] < 0: return x self.parent[x] = self.root(self.parent[x]) return self.parent[x] N, M, K = map(int, input().split()) graph = [[] for _ in range(N)] edges = [] uf = UnionFind(N) for i in range(M): u, v, w = map(int, input().split()) u -= 1 v -= 1 graph[u].append((v, w)) graph[v].append((u, w)) edges.append((u, v, w, i)) used = set() for _ in range(K): e = int(input()) - 1 u, v, w, _ = edges[e] uf.union(u, v) used.add(e) edges.sort(key=lambda x: x[2]) erased = 0 for u, v, w, i in edges: if i in used: continue if not uf.union(u, v): erased += w print(erased)