There are n cities and n - 1 directed roads forming a tree. Reorient the minimum number of roads so that every city can reach city 0.
"Instead of checking if every city can reach 0, start at city 0 and traverse outward to all nodes. The tree structure guarantees every node is reachable via a unique path."
"Store neighbors as pairs: (neighbor, sign). When adding road $u \to v$, store $(v, 1)$ in $u$'s list (meaning road points away from $u$) and $(u, 0)$ in $v$'s list (meaning road points toward $v$)."
"Run DFS from 0 with a parent tracker or visited array. When moving from current city $u$ to child $v$, add the sign to our answer: if sign is 1, the original road points $u \to v$ (away from 0) and must be flipped!"
"Every node and edge in the tree is traversed exactly once. Time is $O(n)$ and space is $O(n)$ for the adjacency list and recursion stack."