Simple Python Solution
\n# Code\n\nclass Solution:\n    def minReorder(self, n: int, connections: List[List[int]]) -> int:\n        dt = defaultdict(list)\n        for a,b in connecti
\n# Code\n```\nclass Solution:\n    def minReorder(self, n: int, connections: List[List[int]]) -> int:\n        dt = defaultdict(list)\n        for a,b in connections:\n            dt[a].append((b,True))\n            dt[b].append((a,False))\n        ans = 0\n        q = [0]\n        vis = set()\n        while(q):\n            node = q.pop()\n            vis.add(node)\n            for nd,st in dt[node]:\n                if nd not in vis:\n                    q.append(nd)\n                    if st: ans+=1\n        return ans\n```
['Python3']