[Python] Count the Connected Networks
Explanation\nWe need at least n - 1 cables to connect all nodes (like a tree).\nIf connections.size() < n - 1, we can directly return -1.\n\nOne trick is that, 
## **Explanation**\nWe need at least `n - 1` cables to connect all nodes (like a tree).\nIf `connections.size() < n - 1`, we can directly return `-1`.\n\nOne trick is that, if we have enough cables,\nwe don\'t need to worry about where we can get the cable from.\n\nWe only need to count the number of connected networks.\nTo connect two unconneccted networks, we need to set one cable.\n\nThe number of operations we need = the number of **connected networks** - 1\n<br>\n\n## **Complexity**\nTime `O(connections)`\nSpace `O(n)`\n<br>\n\n**Python:**\n```python\n    def makeConnected(self, n, connections):\n        if len(connections) < n - 1: return -1\n        G = [set() for i in xrange(n)]\n        for i, j in connections:\n            G[i].add(j)\n            G[j].add(i)\n        seen = [0] * n\n\n        def dfs(i):\n            if seen[i]: return 0\n            seen[i] = 1\n            for j in G[i]: dfs(j)\n            return 1\n\n        return sum(dfs(i) for i in xrange(n)) - 1\n```\n
[]