Expand description
§Digital Plumber
This problem is the classic union-find. A variant of flood fill is used to find the connected groups or cliques.
For each program we depth-first search from each of its neighbors that we have not already seen. If a neighbor has been seen then it must be either already in this clique or in another clique.