java - How do you calculate the number of connected graphs? -
given array of node , array of edges, how calculate number of connected graphs?
you can use union find (you can search up). start of nodes separate sets, each edge join 2 nodes edge connects same set. check how many different sets there going through nodes , finding how many different representatives there are.
Comments
Post a Comment