I need an algorithm to partition the vertices of an undirected graph into one or more subgraphs, such that each subgraph is a complete graph (every vertex adjacent to every other vertex). Each vertex needs to be in exactly one of the subgraphs.
Here's an example:
input = [
(A, B),
(B, C),
(A, C),
(B, D),
(D, E),
]
output = myalgo(input) # [(A, B, C), (D, E)]
Here's an image that better describes the problem:
The input list is sorted in decreasing order by distance, that's why I connect A-B-C instead of B-D.
I thought this might be called "strongly connected components", and have already tried the following solutions:
Finding a Strongly Connected Components in unDirected Graphs: it's looking for something different
Finding all cycles in undirected graphs: it gives me many cycles and not the best, it doesn't care about the input order.
An algorithm to create clusters from data pairs in python: it connects all the components, just because there is a path between them (A-B-C-D-E).
Kosaraju's algorithm: it works only with a directed graph.