Connection
Base URL, credentials and a reachable server.
Compare the edge fixture with the returned groups and account for isolated vertices before connecting component labels to downstream code.
Base URL, credentials and a reachable server.
A model available through the configured endpoint.
Context limits and tool support are determined by the model and server.
def components(count, edges):
if type(count) is not int or not 0 <= count <= 10000:
raise ValueError("node count")
pairs = list(edges)
for pair in pairs:
if len(pair) != 2 or any(type(v) is not int or not 0 <= v < count for v in pair):
raise ValueError("edge endpoint")
parent = list(range(count))
def find(x):
while parent[x] != x:
parent[x] = parent[parent[x]]
x = parent[x]
return x
for a, b in pairs:
parent[find(b)] = find(a)
groups = {}
for node in range(count): groups.setdefault(find(node), []).append(node)
return sorted(groups.values())