|
|
back to boardHint Posted by Frankey 26 Jul 2009 21:25 This is very easy problem. You can use: 1) BFS or DFS to find the components of the graph; 2) Prim or Kruskal algo for minimum spanning tree. Re: Hint spanning tree can be built during BFS. It's correct because graph is unweighted. Re: Hint Well, I see, that this is MST problem, but cannot get how to build a graph for it. Please, explain your step 1 more precisely. Re: Hint Sure, it can be solved applying BFS or DFS + Minimum Spanning Tree algorithms (Prim Algorithm). But, BFS or DFS is enough to solve it. BFS or DFS is implemented to identify Connected Component and Non-Connected Component. No need to apply MST to remove redundant edges in each Connected Component. Because, while BFS or DFS you can built identify which edges you need and don't need. Here is one part of my code to do BFS and work like Prim algo [code deleted] Edited by moderator 19.10.2019 20:33 |
|
|