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

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -