Minimum spanning tree

Write codeMedium35 min

Your task

You must connect n cities (0..n-1) with cables. You are given a list of candidate cables as [u, v, cost]. Return the minimum total cost to connect all cities so that every city is reachable from every other. If it is impossible to connect them all, return -1. The graph is undirected; duplicate cables and self-cables (u == v) may appear.

Examples

min_cable_cost(n: int, cables: list[list[int]]) -> int
Example 1
Inputmin_cable_cost(4, [[0, 1, 1], [1, 2, 2], [2, 3, 3], [0, 3, 10]])
Output6