📌 Python3 DFS solution
\nclass Solution:\n    def makeConnected(self, n: int, a: List[List[int]]) -> int:\n        length = len(a)\n        if length < n - 1:\n            return -1\n
```\nclass Solution:\n    def makeConnected(self, n: int, a: List[List[int]]) -> int:\n        length = len(a)\n        if length < n - 1:\n            return -1\n        nodes = set()\n        connections = defaultdict(list)\n        \n        for src,dest in a:\n            connections[src].append(dest)\n            connections[dest].append(src)\n        \n        def dfs(src):\n            if src in nodes:\n                return\n            nodes.add(src)\n            for node in connections[src]:\n                dfs(node)\n            \n        \n        result = 0\n        for i in range(n):\n            if i not in nodes:\n                dfs(i)\n                result+=1\n        \n        return result - 1\n        \n        \n```
['Depth-First Search', 'Recursion', 'Python3']