Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_reachable(graph, start, end, visited):
- visited.append(start)
- if start is end:
- return True
- for next_node in graph[start]:
- if end is next_node:
- return True
- else:
- if next_node not in visited and is_reachable(graph, next_node, end, visited):
- return True
- return False
- def reachable(graph, node):
- result = []
- for n in graph:
- if is_reachable(graph, node, n, []):
- result.append(n)
- return result
Add Comment
Please, Sign In to add comment