結果
| 問題 |
No.748 yuki国のお財布事情
|
| コンテスト | |
| ユーザー |
compass19
|
| 提出日時 | 2018-10-19 23:20:16 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,568 bytes |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 385,132 KB |
| 最終ジャッジ日時 | 2024-11-18 22:39:34 |
| 合計ジャッジ時間 | 17,201 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 6 WA * 18 TLE * 2 |
ソースコード
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] |= Children[Root[b]]
elif Root[a] == a and Root[b] != b:
for c in Children[Root[b]]:
Root[c] = Root[a]
Children[Root[a]] |= Children[Root[b]]
else:
for c in Children[Root[a]]:
Root[c] = Root[b]
Children[Root[b]] |= Children[Root[a]]
is_finish = False
for n in range(N):
if len(Children[n]) == N:
is_finish = True
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] |= Children[Root[b]]
if len(Children[a]) == N:
is_finish = True
elif Root[a] == a and Root[b] != b:
for c in Children[Root[b]]:
Root[c] = Root[a]
Children[Root[a]] |= Children[Root[b]]
if len(Children[Root[a]]) == N:
is_finish = True
else:
for c in Children[Root[a]]:
Root[c] = Root[b]
Children[Root[b]] |= Children[Root[a]]
if len(Children[Root[b]]) == N:
is_finish = True
print(del_weight)
compass19