[Python] 7-line DFS solution
python\ndef minReorder(self, n: int, connections: List[List[int]]) -> int:\n    edges = collections.defaultdict(list)\n    for a, b in connections:\n        edg
```python\ndef minReorder(self, n: int, connections: List[List[int]]) -> int:\n    edges = collections.defaultdict(list)\n    for a, b in connections:\n        edges[a].append((b, 1))\n        edges[b].append((a, 0))\n\n    def dfs(i, p):\n        return sum(d + dfs(j, i) for j, d in edges[i] if j != p)\n\n    return dfs(0, -1)\n```
['Depth-First Search', 'Python']