[Python] Clean dfs with explanations
Let us put all the edges into adjacency list twice, one with weight 1 and one with weight -1 with oppisite direction. Then what we do is just traverse our graph
Let us put all the edges into adjacency list twice, one with weight `1` and one with weight `-1` with oppisite direction. Then what we do is just traverse our graph using usual dfs, and when we try to visit some neighbour, we check if this edge is usual or reversed.\n\n**Complexity** is `O(V+E)`, because we traverse our graph only once.\n\n```\nclass Solution:\n    def dfs(self, start):\n        self.visited[start] = 1\n        for neib in self.adj[start]:\n            if self.visited[neib[0]] == 0:\n                if neib[1] == 1:\n                    self.count += 1\n                self.dfs(neib[0])\n    \n    def minReorder(self, n, connections):\n        self.visited = [0] * n\n        self.adj = defaultdict(list) \n        self.count = 0\n        for i, j in connections:\n            self.adj[i].append([j,1])\n            self.adj[j].append([i,-1])\n\n        self.dfs(0)\n        return self.count\n```\n\nIf you have any questions, feel free to ask. If you like solution and explanations, please **Upvote**!
[]