#C1503. Minimum Garden Connection Effort
Minimum Garden Connection Effort
Minimum Garden Connection Effort
You are given an undirected weighted graph representing a garden. The graph has V vertices and E edges. Each edge is described by three integers u, v, and w, representing an edge between vertices u and v with a weight (or effort) w.
Your task is to compute the minimum total effort required to connect all points in the garden. In other words, you should find the cost of the Minimum Spanning Tree (MST) of the graph. The total effort of the MST is given by:
\( \text{Total Effort} = \sum_{e \in MST} w_e \)
You can assume that the input graph is connected (or if it is a single node, there will be no edges). Use an efficient algorithm such as Kruskal's algorithm with union-find to solve the problem.
inputFormat
The first line contains two integers V
and E
separated by a space, where V
is the number of vertices and E
is the number of edges.
The following E
lines each contain three integers u v w
separated by spaces, representing an edge from vertex u
to vertex v
with weight w
.
Note: Vertices are numbered starting from 1.
outputFormat
Output a single integer — the minimum total effort required to connect all the points in the garden.
## sample4 5
1 2 1
1 3 4
2 3 2
2 4 3
3 4 5
6