原题链接在这里:https://leetcode.com/problems/connecting-cities-with-minimum-cost/ 题目: There areNcities numbered from 1 toN. You are givenconnections, where eachconnections[i] = [city1, city2, cost]represents the cost to connectcity1andcity2together. (Aconnectionis bidirectional: connectingcit...
原题链接在这里:https://leetcode.com/problems/connecting-cities-with-minimum-cost/ 题目: There areNcities numbered from 1 toN. You are givenconnections, where eachconnections[i] = [city1, city2, cost]represents the cost to connectcity1andcity2together. (Aconnectionis bidirectional: connectingcit...
一个union函数,一个find函数,哦了。 https://leetcode.com/problems/connecting-cities-with-minimum-cost/discuss/344867/Java-Kruskal's-Minimum-Spanning-Tree-Algorithm-with-Union-Find classSolution {int[] parent;intn;privatevoidunion(intx,inty) {intpx =find(x);intpy =find(y);if(px !=py) { ...