Reorder Routes to Make All Paths Lead to the City Zero

Medium · Graphs · about 20 minutes

Asked at Google, Amazon, Meta, Microsoft, ByteDance.

n cities 0..n-1 are connected by n - 1 one-way roads forming a tree (if the directions are ignored); connections[i] = [a, b] is a road from a to b. Return the minimum number of roads to reverse so that every city can reach city 0.

Related guides