[Kotlin] Dfs
First, create adjacency list. The trick is to mark in directed roads with minus.\nThis will help us to distinguish them from out directed roads on our way.\n\nT
First, create adjacency list. The trick is to mark `in` directed roads with minus.\nThis will help us to distinguish them from `out` directed roads on our way.\n\nThen do dfs and count how many of the roads are `out`.\n\n```\nclass Solution {\n    fun minReorder(n: Int, connections: Array<IntArray>): Int {\n        val adj  = mutableMapOf<Int, MutableList<Int>>()\n\n        for ((a, b) in connections) {\n            adj.getOrPut(a, { mutableListOf() }) += b\n            adj.getOrPut(b, { mutableListOf() }) += (-a)\n        }\n\n        val vis = mutableSetOf<Int>()\n        vis += 0\n\n        fun dfs(a: Int): Int {\n            var cnt = 0\n\n            for (b in adj[a]!!) {\n                if (vis.add(Math.abs(b))) {\n                    cnt += dfs(Math.abs(b))\n                    if (b > 0) cnt++\n                }\n            }\n\n            return cnt\n        }\n\n        return dfs(0)\n    }\n}\n```
['Kotlin']