A weighted, undirected graph on n vertices is given as edges[i] = [u, v, weight] (no self-loops, parallel edges allowed). The second-best spanning tree is the cheapest spanning tree that is not the minimum spanning tree you started from. If the MST is not unique, another tree of the same weight is itself a second-best tree.
Write secondBestMSTWeight(n, edges) returning the weight of the second-best spanning tree, or -1 when there is none: the graph is disconnected, or it is already a tree with no spare edge.