Counting all connected nodes in graph
问题 I have a >10k list of (unordered) pairs of numbers. I'd like to classify them into sets of connected pairs either directly or indirectly. I think this corresponds to undirected graph. I'm using python, and tried something like this to represent this structure. In order to know all the numbers connected to i , I can examine whether there is a path from i to j for all j in the list except i . However, with this implementation, the computation time gets too long for the size of list I'm dealing