Python Kruskal's Algorithm
```\nclass Solution:\n    def makeConnected(self, n: int, connections: List[List[int]]) -> int:\n        # you need at least n - 1 edges to connect n nodes\n   
```\nclass Solution:\n    def makeConnected(self, n: int, connections: List[List[int]]) -> int:\n        # you need at least n - 1 edges to connect n nodes\n        if n - 1 > len(connections):\n            return -1\n        \n        link = list(range(n))\n        size = n * [1]\n        conCount = 1\n        \n        def find(x):\n            while x != link[x]:\n                x = link[x]\n            return x\n        \n        def same(a, b):\n            return find(a) == find(b)\n        \n        def unite(a, b):\n            a, b = find(a), find(b)\n            if size[a] < size[b]:\n                a, b = b, a\n            size[a] += size[b]\n            link[b] = a\n        \n        for a, b in connections:\n            if not same(a, b):\n                unite(a, b)\n                conCount += 1\n        \n        return n - conCount
['Union Find', 'Python']