[Kotlin] Bfs, count connected components.
\n    fun makeConnected(n: Int, connections: Array<IntArray>): Int {\n        if (connections.size < n - 1) return -1\n\n        val adj = mutableMapOf<Int, Mut
```    \n    fun makeConnected(n: Int, connections: Array<IntArray>): Int {\n        if (connections.size < n - 1) return -1\n\n        val adj = mutableMapOf<Int, MutableList<Int>>()\n        for ((a, b) in connections) {\n            adj.getOrPut(a) { mutableListOf() } += b\n            adj.getOrPut(b) { mutableListOf() } += a\n        }\n\n        var components = 0\n        val vis = mutableSetOf<Int>()\n        val q = LinkedList<Int>()\n\n        for (key in adj.keys) {\n            if (key in vis) continue\n \n            q.offer(key)\n\n            while (q.isNotEmpty()) {\n                val cur = q.poll()\n                if (vis.add(cur)) q.addAll(adj[cur]!!)\n            }\n\n            components++\n        }\n\n        return components + (n - vis.size) - 1\n    }\n```
['Breadth-First Search', 'Kotlin']