結果
問題 | No.748 yuki国のお財布事情 |
ユーザー | compass19 |
提出日時 | 2018-10-19 22:59:26 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,441 bytes |
コンパイル時間 | 620 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 377,044 KB |
最終ジャッジ日時 | 2024-11-18 22:11:42 |
合計ジャッジ時間 | 34,787 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 30 ms
17,956 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | TLE | - |
testcase_15 | WA | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 29 ms
10,880 KB |
testcase_23 | WA | - |
testcase_24 | AC | 28 ms
10,880 KB |
testcase_25 | WA | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
ソースコード
N, M, K = map(int, input().split()) citys = {n: {'Root': n, 'child': {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} # union tree for e in abs_edges: a, b, _ = edges[e] # print(a, b) if citys[a]['Root'] == a and citys[b]['Root'] == b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = a citys[a]['child'].add(c) elif citys[a]['Root'] == a and citys[b]['Root'] != b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = citys[a]['Root'] citys[citys[a]['Root']]['child'].add(c) else: for c in citys[citys[a]['Root']]['child']: citys[c]['Root'] = citys[b]['Root'] citys[citys[b]['Root']]['child'].add(c) del_weight = 0 for ix, e in enumerate(sorted_edges): # edge eを追加できるかどうか a, b, c = edges[e] print(ix+1, a, b, c) if citys[a]['Root'] == citys[b]['Root']: del_weight += c continue if citys[a]['Root'] == a and citys[b]['Root'] == b: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = a citys[a]['child'].add(c) else: for c in citys[citys[b]['Root']]['child']: citys[c]['Root'] = citys[a]['Root'] citys[citys[a]['Root']]['child'].add(c) print(del_weight)