95. Minimum Spanning Tree Weight (Kruskal)
MediumDisjoint sets
An undirected weighted graph has n vertices numbered 0 to n − 1 and edges given as [u, v, w]. Return the total weight of a minimum spanning tree, or -1 if the graph is not connected.
Example 1
Input: n = 4, edges = [[0,1,1],[1,2,2],[0,2,3],[2,3,4]] Output: 7
Constraints
1 ≤ n ≤ 10⁴0 ≤ edges.length ≤ 10⁵Weights may be negative