Find the MST Weight
Given a connected undirected graph with V vertices numbered 0 through V - 1, return the minimum total weight of a spanning tree. A spanning tree connects…
Given a connected undirected graph with V vertices numbered 0 through V - 1, return the minimum total weight of a spanning tree. A spanning tree connects every vertex and contains no cycle. The callable receives reciprocal adjacency: adj[u] contains [v, weight] for each edge occurrence incident to u. Each logical input edge contributes two entries, including a loop. Positive loops and parallel edge occurrences are explicitly supported by this local contract. They are not extra guarantees attributed to the source publisher. Return only the total weight, not a particular tree. Tied minimum trees are equally valid. Do not mutate the caller's adjacency.
2 ≤ V ≤ 1000. V - 1 ≤ E ≤ 10000 logical undirected edge occurrences; reciprocal adjacency contains exactly 2E entries. Endpoints lie in 0..V - 1 and every weight lies in 1..100000. The graph is connected. The largest possible answer is 99900000. Visualization uses at most 12 vertices, 24 occurrences and weights through 10000; these are visual-only limits, not coding limits.
Example 1: input V = 4, adj = [[[1,1],[3,4]],[[0,1],[2,2]],[[1,2],[3,3]],[[2,3],[0,4]]]; output 6. Edges of weights 1, 2 and 3 connect all four vertices at total cost 6.
Example 2: input V = 3, adj = [[[1,5],[2,15]],[[0,5],[2,10]],[[0,15],[1,10]]]; output 15. Choose weights 5 and 10; the alternative weight 15 edge is unnecessary.
Category: Graphs. Topic: graph. Difficulty: Hard. Patterns: graph-traversal.