Python | Easy Solution with Explanation | BFS
\n# Approach: First check if total number of edges available in network is greater or equal to n-1 (n is number of nodes). If not, then return -1, because it is
```\n# Approach: First check if total number of edges available in network is greater or equal to n-1 (n is number of nodes). If not, then return -1, because it is theoretically not possible to connect all the nodes with less edges. Else, find total\n# number of isolated clusters (you can use BFS, DFS, Union-Find). Here we have used BFS to find total isolated clusters. Finally, we will require (total_clusters - 1) number of wires to connect them all.\n\nfrom collections import deque\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        \n        if len(connections) < n - 1:\n            return -1\n        \n        cluster, queue, graph, visited = 0, deque([]), [[] for i in range(n)], set([])\n        \n        # Creating Graph\n        for c in connections:\n            graph[c[0]].append(c[1])\n            graph[c[1]].append(c[0])\n            \n        # Counting isolated clusters using BFS\n        for i in range(n):\n            if i not in visited:\n                cluster += 1\n                queue.append(i)\n                visited.add(i)\n                \n                # BFS\n                while queue:\n                    node = queue.popleft()\n                    \n                    for nhbrs in graph[node]:\n                        if nhbrs not in visited:\n                            queue.append(nhbrs)\n                            visited.add(nhbrs)\n        \n        # Counting Min number of times to get connections\n        return (cluster - 1)\n```
['Breadth-First Search', 'Python']