結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
compass19
|
| 提出日時 | 2018-10-20 00:19:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 856 bytes |
| コンパイル時間 | 98 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 48,164 KB |
| 最終ジャッジ日時 | 2024-11-18 23:22:24 |
| 合計ジャッジ時間 | 12,683 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 RE * 10 |
ソースコード
N, M, K = map(int, input().split())
Root = [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
def get_Root(c):
if Root[c] == c:
return c
else:
return get_Root(Root[c])
def merge(a, b):
if Root[a] == a:
Root[get_Root(b)] = a
elif Root[b] == b:
Root[get_Root(a)] = b
else:
Root[get_Root(b)] = Root[get_Root(a)]
# 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)
compass19