HHopwise
Product

Product features · Directed shortest hop counts

01

Trace hop_distances.py to distinguish a zero-distance starting vertex from an unreachable vertex.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Directed shortest hop counts

● ● ●Hopwise●
A concrete starting point · Directed shortest hop counts ×
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
✳Directed shortest hop counts
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗