A city has n intersections, numbered 1..n, joined by n - 1 one-way streets. Ignoring the directions, the streets form a tree. Street i runs from frm[i] to to[i].
The city wants to pick one intersection as a dispatch hub and then flip the direction of as few streets as possible so that every street points away from the hub (so every intersection can be reached from the hub by driving forwards).
Write min_reversals(n: int, frm: list[int], to: list[int]) -> int that returns the fewest flips needed, taking the best possible hub.
min_reversals(4, [2, 2, 4], [1, 3, 3])
# 1: streets 2->1, 2->3, 4->3. Hub 2 needs only 4->3 flipped (hub 4 also needs just one flip).
min_reversals(3, [1, 2], [2, 3]) # 0 (hub 1: 1->2->3 already points away)
min_reversals(1, [], []) # 0
Constraints: 1 <= n <= 10**5. Trying every hub and walking the whole tree from each is O(n²) and too slow. The tree may be a single path 10**5 long, so a recursive DFS will hit Python's recursion limit; use an explicit stack or BFS.
Show hint
Compute the answer for hub 1 with one traversal. Then ask how that number changes when the hub moves across a single street to a neighbour.