Prim - MST - Hackerrank Problem Solution

Prim - MST
Hackerrank Problem Solution
Prim MST - Hackerrank Solution
PROBLEM STATEMENT

Given an undirected weighted connected graph, find the MST in it. The MST is defined as a subgraph consisting of all the vertices in the graph and: • There is only one exclusive path from a vertex to every other vertex. • The subgraph is of minimum overall weight among all subgraphs. • No cycles are created. One specific vertex S is fixed as the starting point of finding the subgraph using Prim's Algorithm. Prim’s method has the following parameter(s):

v: an integer that represents the number of vertices in the graph e: a two-dimensional array where each element contains three integers, two nodes numbers that are connected and the weight of that edge.

Input Format

The first line has two integers n and m, the number of vertices and edges in the graph.

Each of the next ‘m’ lines contains three integers x, y and r, the end nodes of e[i], and the edge's weight.

Constraints

image

Output Format

Print a single integer denoting the total weight of the MST.

Sample Input 0

3 3
1    2    1
2    3    2
3    1    4

Sample Output 0

3


SOLUTION IN C
SHARE If you find this useful, please share with your friends and Community.
CODE TOGETHER..GROW TOGETHER.
Newer Posts Newer Posts Older Posts Older Posts

More posts

Comments

Post a Comment

Sponsored Content