Breadth-first search
Approach\nFirst create a lookup dictionary adj that maps vertices to adjacent/contiguous edges. Initialize 0 as the current vertex set curr and the set seen of 
# Approach\nFirst create a lookup dictionary `adj` that maps vertices to adjacent/contiguous edges. Initialize 0 as the current vertex set `curr` and the set `seen` of vertices that have been visited. Iteratively update `curr` by adding vertices adjacent to the current set if they have not already been seen. Edges `e` where `e[1] in curr` and `e[0] not in seen` are already pointing in the correct direction; edges `e` where `e[0] in curr` and `e[1] not in seen`must be flipped. Keep track of the flips `s` and return the total when there are no more vertices in `curr`.\n\n# Code\n```python\nclass Solution:\n    def minReorder(self, n: int, connections: List[List[int]]) -> int:\n        s = 0\n        # create dictionary mapping vertices to their adjacent edges\n        adj = defaultdict(list)\n        for c in connections:\n            adj[c[0]].append(c)\n            adj[c[1]].append(c)\n\n        # run the search\n        curr = seen = {0}\n        while curr:\n            new = set()  # will contain neighbors of `curr` not in `seen`\n            for v in curr:\n                for e in adj[v]:\n                    if e[0] not in seen and e[1] == v:\n                        # pointing the \'right\' direction\n                        new.add(e[0])\n                    elif e[0] == v and e[1] not in seen:\n                        # pointing the \'wrong\' direction\n                        new.add(e[1])\n                        s += 1\n            curr = new\n            seen.update(new)\n\n        return s\n```
['Breadth-First Search', 'Python3']