結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | compass19 |
提出日時 | 2018-10-19 23:17:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
MLE
(最新)
TLE
(最初)
|
実行時間 | - |
コード長 | 1,684 bytes |
コンパイル時間 | 99 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 563,232 KB |
最終ジャッジ日時 | 2024-11-18 22:31:52 |
合計ジャッジ時間 | 33,397 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
17,824 KB |
testcase_01 | AC | 27 ms
187,692 KB |
testcase_02 | AC | 27 ms
17,700 KB |
testcase_03 | AC | 27 ms
421,888 KB |
testcase_04 | AC | 26 ms
16,256 KB |
testcase_05 | MLE | - |
testcase_06 | AC | 27 ms
17,952 KB |
testcase_07 | AC | 27 ms
378,576 KB |
testcase_08 | AC | 27 ms
17,828 KB |
testcase_09 | AC | 28 ms
452,592 KB |
testcase_10 | AC | 29 ms
17,952 KB |
testcase_11 | AC | 29 ms
455,068 KB |
testcase_12 | AC | 27 ms
17,952 KB |
testcase_13 | AC | 219 ms
419,148 KB |
testcase_14 | TLE | - |
testcase_15 | AC | 631 ms
461,604 KB |
testcase_16 | TLE | - |
testcase_17 | MLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 27 ms
10,880 KB |
testcase_23 | AC | 25 ms
11,008 KB |
testcase_24 | AC | 27 ms
11,008 KB |
testcase_25 | AC | 490 ms
35,204 KB |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
ソースコード
N, M, K = map(int, input().split()) Root = [n for n in range(N)] Children = [{n} 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 # union tree for e in abs_edges: a, b, _ = edges[e] if Root[a] == a and Root[b] == b: for c in Children[Root[b]]: Root[c] = a Children[a].add(c) elif Root[a] == a and Root[b] != b: for c in Children[Root[b]]: Root[c] = Root[a] Children[Root[a]].add(c) else: for c in Children[Root[a]]: Root[c] = Root[b] Children[Root[b]].add(c) is_finish = False for n in range(N): if len(Children[n]) == N: is_finish = True # exit() for e in sorted_edges: # edge eを追加できるかどうか a, b, c = edges[e] if is_finish or Root[a] == Root[b]: del_weight += c continue if Root[a] == a and Root[b] == b: for c in Children[Root[b]]: Root[c] = a Children[a].add(c) if len(Children[a]) == N: # print('A', del_weight) is_finish = True elif Root[a] == a and Root[b] != b: for c in Children[Root[b]]: Root[c] = Root[a] Children[Root[a]].add(c) if len(Children[Root[a]]) == N: # print('B', del_weight) # exit() is_finish = True else: for c in Children[Root[a]]: Root[c] = Root[b] Children[Root[b]].add(c) if len(Children[Root[b]]) == N: is_finish = True # print(Children[Root[b]]) # print('C', del_weight) # exit() # for n in range(N): # print(Children[n]) print(del_weight)