Reorder Routes to Make All Paths Lead to the City Zero
There are `n` cities numbered `0` to `n - 1` and `n - 1` one-way roads, so that there is exactly one way to travel between any two cities if road directions are ignored (the roads form a tree). `connections[i] = [a_i, b_i]` is a road from `a_i` to `b_i`. The capital is city 0. Reorient the fewest roads so that every city can reach city 0, and return that number. It is guaranteed that after reordering, every city can reach city 0.
30:00
Reorder Routes to Make All Paths Lead to the City Zero
There are n cities numbered 0 to n - 1 and n - 1 one-way roads, so that there is exactly one way to travel between any two cities if road directions are ignored (the roads form a tree). connections[i] = [a_i, b_i] is a road from a_i to b_i. The capital is city 0. Reorient the fewest roads so that every city can reach city 0, and return that number. It is guaranteed that after reordering, every city can reach city 0.