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

Popular posts from this blog

python - Why doesn't list have safe "get" method like dictionary? -

razor - Is this a bug in WebMatrix PageData? -

sql server - Stored procedure -