Python 3 95% speed
\n\n# Code\n\nclass Solution:\n    def minReorder(self, n: int, connections: List[List[int]]) -> int:\n        graph = defaultdict(set)\n        for a, b in con
\n\n# Code\n```\nclass Solution:\n    def minReorder(self, n: int, connections: List[List[int]]) -> int:\n        graph = defaultdict(set)\n        for a, b in connections:\n            graph[a].add((b, True))\n            graph[b].add((a, False))\n        \n        queue = deque([(0, False)])\n        ans = 0\n        visited = set()\n        while queue:\n            city, needs_flipped = queue.popleft()\n            visited.add(city)\n            if needs_flipped:\n                ans += 1\n            for neighbour in graph[city]:\n                if neighbour[0] not in visited:\n                    queue.append(neighbour)\n        return ans\n\n\n```
['Python3']