Prim's Minimum Spanning Tree (mst).

easy
      1.You will be given an graph represented in form of ArrayList<ArrayList<edge>>, where edge is a user defined class  (a type) which contains three Integer data members:
	1st : v1 (denotes) vertex1.
	2nd : v2 (denotes) vertex2.
	3rd : wt (denotes the weight of edge b/w v1 and v2).
	(we have constructed this representation of graph in 1st question)
	
2. You will be given a graph, The idea behind Prim's algorithm is simple, a spanning tree means all vertices must be connected. A spanning tree is a subset of Graph G, which has all the vertices covered with minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be disconnected and they must be connected with the minimum weight edge to make it a Minimum Spanning Tree.
                               
                               
                               
                               
                               
                               

Input Format

1.First line consist a graph.

Output Format

1.Display a graph (ArrayList<ArrayList<edge>>)

Constraints

 0 <= a < graphs size

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
...
Output
0->[1 @ 10],
1->[0 @ 10], [2 @ 10],
2->[1 @ 10], [3 @ 10],
3->[2 @ 10], [4 @ 2],
4->[3 @ 2], [5 @ 3],
5->[4 @ 3], [6 @ 3],
6->[5 @ 3],
Previous
F1201_lecture1_gcc
Next
Paint House

Related Questions