Connecting Cities With Minimum Cost
There are
n cities labeled from 1 to n. You are given an array connections where connections[i] = [u, v, cost] represents a bidirectional road between city u and city v with a given cost. Your task is to find the minimum cost to connect all cities such that there is at least one path between any two cities. If it is impossible to connect all cities, return -1. Constraints: 1 <= n <= 10,000 1 <= connections.length <= 10,000 1 <= cost <= 10^5 Each connection [u, v, cost] satisfies 1 <= u, v <= n and u != v.JavaKruskal's AlgorithmUnion-Find
00