Python DFS, this question is similar to the number of islands
This question can be thought as calculating the number of groups. Group is computers that are connected with each other.\n\n```\ndef makeConnected(self, n: int,
This question can be thought as calculating the number of groups. Group is computers that are connected with each other.\n\n```\ndef makeConnected(self, n: int, connections: List[List[int]]) -> int:\n        if len(connections) < n - 1:\n            return -1\n        res = 0\n        self.connect = collections.defaultdict(list)\n        for c in connections:\n            self.connect[c[0]].append(c[1])\n            self.connect[c[1]].append(c[0])\n        self.visited = [0] * n\n        for i in range(n):\n            if not self.visited[i]:\n                res += 1\n                self.dfs(i)\n                \n        return res - 1\n    \n    def dfs(self,i):\n        if self.visited[i]:\n            return\n        self.visited[i] = 1\n        for neighbour in self.connect[i]:\n            self.dfs(neighbour)
[]