Maximum spanning tree weight
Given a connected-or-not undirected weighted graph with n nodes (0..n-1) and edges [w, u, v] (weight first), return the total weight of a maximum spanning tree: a spanning tree maximizing the sum of chosen edge weights. If the graph is not connected (no spanning tree exists), return -1. A single node with no edges has weight 0. Constraints: 1 <= n <= 1000.
Implement
max_spanning_tree_weight(n: int, edges: list[list[int]]) → intExamples
in
[3,[[1,0,1],[2,1,2],[3,0,2]]]out5What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[3,[[1,0,1],[2,1,2],[3,0,2]]]5not run yetsample