Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def connected_components(node_iterator, possible_moves):
- components = list()
- seen = set()
- for node in node_iterator:
- if node not in seen:
- queue = deque([node])
- component = set()
- while queue:
- current = queue.popleft()
- assert(current not in seen)
- component.add(current)
- for nnext in possible_moves(current) - seen:
- queue.push(nnext)
- components.append(component)
Add Comment
Please, Sign In to add comment