Minimum road reversals to capital
Your task
There are n cities (0..n-1) connected by n-1 one-way roads forming a tree if you ignore direction. City 0 is the capital. Each road is given as [a, b] meaning a directed road from a to b. You can reverse the direction of any road. Return the minimum number of roads you must reverse so that every city can reach the capital (city 0). 1 <= n.
Examples
min_reorder_to_capital(n: int, connections: list[list[int]]) -> intExample 1
Input
min_reorder_to_capital(6, [[0, 1], [1, 3], [2, 3], [4, 0], [4, 5]])Output
3