結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | compass19 |
提出日時 | 2018-10-20 00:23:38 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 691 ms / 2,000 ms |
コード長 | 989 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 10,840 KB |
実行使用メモリ | 45,748 KB |
最終ジャッジ日時 | 2023-08-12 03:04:40 |
合計ジャッジ時間 | 8,445 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
8,232 KB |
testcase_01 | AC | 16 ms
8,340 KB |
testcase_02 | AC | 15 ms
8,196 KB |
testcase_03 | AC | 16 ms
8,176 KB |
testcase_04 | AC | 17 ms
8,204 KB |
testcase_05 | AC | 16 ms
8,320 KB |
testcase_06 | AC | 16 ms
8,164 KB |
testcase_07 | AC | 16 ms
8,316 KB |
testcase_08 | AC | 16 ms
8,340 KB |
testcase_09 | AC | 16 ms
8,208 KB |
testcase_10 | AC | 16 ms
8,292 KB |
testcase_11 | AC | 16 ms
8,324 KB |
testcase_12 | AC | 16 ms
8,168 KB |
testcase_13 | AC | 84 ms
12,136 KB |
testcase_14 | AC | 143 ms
16,312 KB |
testcase_15 | AC | 99 ms
13,132 KB |
testcase_16 | AC | 265 ms
22,692 KB |
testcase_17 | AC | 522 ms
36,592 KB |
testcase_18 | AC | 637 ms
40,516 KB |
testcase_19 | AC | 691 ms
45,748 KB |
testcase_20 | AC | 603 ms
43,116 KB |
testcase_21 | AC | 621 ms
40,900 KB |
testcase_22 | AC | 16 ms
8,180 KB |
testcase_23 | AC | 15 ms
8,288 KB |
testcase_24 | AC | 16 ms
8,308 KB |
testcase_25 | AC | 497 ms
32,340 KB |
testcase_26 | AC | 623 ms
41,616 KB |
testcase_27 | AC | 609 ms
40,688 KB |
testcase_28 | AC | 454 ms
30,804 KB |
ソースコード
N, M, K = map(int, input().split()) Root = [n for n in range(N)] Root_num = [1 for n in range(N)] edges = [None for _ in range(M)] for m in range(M): a, b, c = map(int, input().split()) edges[m] = (a-1, b-1, c) abs_edges = set(int(input())-1 for _ in range(K)) sorted_edges = sorted([e for e in set(range(M)) - abs_edges], key=lambda x: edges[x][2]) # 最小木 T = {edges[e] for e in abs_edges} del_weight = 0 def get_Root(c): if Root[c] == c: return c else: return get_Root(Root[c]) def merge(a, b): root_a = get_Root(a) root_b = get_Root(b) if Root_num[root_a] < Root_num[root_b]: Root[root_a] = Root[root_b] Root_num[root_b] += Root_num[root_a] else: Root[root_b] = Root[root_a] Root_num[root_a] += Root_num[root_b] # union tree for e in abs_edges: a, b, c = edges[e] merge(a, b) for e in sorted_edges: # edge eを追加できるかどうか a, b, c = edges[e] if get_Root(a) == get_Root(b): del_weight += c continue merge(a, b) print(del_weight)