HHopwise
製品

ソフトウェアの機能 · 有向グラフの最小ホップ数

01

hop_distances.pyをたどり、距離ゼロの開始頂点を到達不能な頂点から区別します。

01

モデル

OpenAI互換またはAnthropicのエンドポイントを、ベースURLと必要なAPIキーで設定し、接続をテストします。ローカルのモデルサーバーは起動が必要です。リモートツールは別途データを送信する場合があります。

02

プロジェクト

フォルダーを選び、編集前に関連ファイルを読むようアシスタントに依頼します。作業の目的と変更範囲を明確にしてください。

03

変更内容

変更内容とコマンド出力を確認します。結果を採用する前にプロジェクトの検証を実行してください。生成コードが自動的にテスト済みになるわけではありません。

有向グラフの最小ホップ数

● ● ●Hopwise●
ワークフロー · 有向グラフの最小ホップ数 ×
from collections import deque

def hop_distances(graph, start):
    if type(graph) is not list or not 1 <= len(graph) <= 1000:
        raise ValueError("graph.size")
    n = len(graph)
    if type(start) is not int or not 0 <= start < n:
        raise ValueError("graph.start")
    if any(type(row) is not list or any(type(v) is not int or
           not 0 <= v < n for v in row) for row in graph):
        raise ValueError("graph.edges")
    distances = [None]*n
    distances[start] = 0
    queue = deque([start])
    while queue:
        u = queue.popleft()
        for v in graph[u]:
            if distances[v] is None:
                distances[v] = distances[u]+1
                queue.append(v)
    return distances
✳有向グラフの最小ホップ数
✓ 変更内容適用前に確認 ↗
ワークスペースのイメージ
AIコーディングワークスペース

次のアイデアはここから。

Windows版をダウンロード ↗