 All Problems
Reorder Routes to Make All Paths Lead to City Zero
medium
graphs
dfs
bfs
amazon
google
microsoft

There are n cities connected by n-1 directed roads (connections). Reorder the minimum number of roads so every city can reach city 0. Return the minimum number of roads to reorder.

Example 1:

Input:
6 5
0 1
1 3
2 3
4 0
4 5
Output: 3

Input format: Line 1: n edges. Next edges lines: a b (directed edge a->b).

Output format: Minimum reorders.

Run to check your code against the sample cases, or submit to run every case