アプリをダウンロード
フォルダーを選び、編集前に関連ファイルを読むようアシスタントに依頼します。作業の目的と変更範囲を明確にしてください。
最大64ノードと±10^9内の整数重みを持つ1024辺から最小全域森を求めてください。非連結ノード、多重辺、自己ループ、同点の決定的選択を試し、不正端点や真偽値を入力を変えず拒否してください。
フォルダーを選び、編集前に関連ファイルを読むようアシスタントに依頼します。作業の目的と変更範囲を明確にしてください。
対応するエンドポイントを選択します。利用できるツールや回答品質は、設定したモデルとサーバーに依存します。
変更内容とコマンド出力を確認します。結果を採用する前にプロジェクトの検証を実行してください。生成コードが自動的にテスト済みになるわけではありません。
実際の動作を期待する結果と比較します。検証に失敗した場合は、次の変更を加える前に原因を調べてください。
def spanning_forest(count, edges):
if type(count) is not int or not 0 <= count <= 64 or type(edges) is not list or len(edges) > 1024:
raise ValueError("forest.input")
ordered = []
for edge in edges:
if type(edge) not in (list, tuple) or len(edge) != 3 or any(type(x) is not int for x in edge):
raise ValueError("forest.edge")
a, b, weight = edge
if not 0 <= a < count or not 0 <= b < count or abs(weight) > 10**9:
raise ValueError("forest.bounds")
ordered.append((weight, min(a, b), max(a, b)))
parent = list(range(count))
def root(node):
while parent[node] != node:
parent[node] = parent[parent[node]]
node = parent[node]
return node
selected, total = [], 0
for weight, a, b in sorted(ordered):
x, y = root(a), root(b)
if x != y:
parent[x] = y
selected.append((a, b, weight))
total += weight
return total, selected
適用前に確認. 変更内容とコマンド出力を確認します。結果を採用する前にプロジェクトの検証を実行してください。生成コードが自動的にテスト済みになるわけではありません。