Python DFS + Union Find Soln
\nclass Solution(object):\n    def makeConnected(self, n, connections):\n        """\n        :type n: int\n        :type connections: List[List[int]]\n        
```\nclass Solution(object):\n    def makeConnected(self, n, connections):\n        """\n        :type n: int\n        :type connections: List[List[int]]\n        :rtype: int\n        """\n        if len(connections) < n - 1:\n            return -1\n        \n        parent = [-1] * n\n\n        def find(x):\n            if parent[x] == -1:\n                return x\n            parent[x] = find(parent[x])\n            return parent[x]\n        \n        def union(x, y):\n            parentX = find(x)\n            parentY = find(y)\n            if parentX != parentY:\n                parent[parentY] = parentX\n            \n        for a, b in connections:\n            union(a, b)\n        \n        count = 0\n        for i in parent:\n            if i < 0:\n                count += 1\n        return count - 1\n                \n               \n        """\n        # DFS solution\n        \n        if len(connections) < n - 1:\n            return -1\n        \n        def dfs(node, graph, visited):\n            visited.add(node)\n            for neighbor in graph[node]:\n                if neighbor not in visited:\n                    dfs(neighbor, graph, visited)\n        \n        graph = collections.defaultdict(list)\n        for a,b in connections:\n            graph[a].append(b)\n            graph[b].append(a)\n            \n        count = 0\n        visited = set()\n        for i in range(n):\n            if i not in visited:\n                dfs(i, graph, visited)\n                count += 1\n        return count - 1\n        """\n```
[]