Question
Given n nodes labeled 0..n-1 and a list of weighted undirected edges [u, v, w], return the total weight of a minimum spanning tree. When several edges have equal weight the choice does not affect total weight, but break ties deterministically by (weight, u, v). If the graph is disconnected and no spanning tree exists, return -1. A single node with no edges has MST weight 0.
mst_weight(n: int, edges: list[list[int]]) → int[4,[[0,1,1],[1,2,2],[2,3,3],[0,3,4]]]out6State 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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.