HHopwise
Workflows

Coding workflows · Directed shortest hop counts

03
Built around your work

A concrete starting point

Calculate shortest directed hop counts from one vertex in a graph of 1 to 1000 vertices. Check cycles, repeated edges and unreachable vertices, rejecting an empty graph or invalid endpoints before traversal.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Directed shortest hop counts

A concrete starting point
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

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗