Search⌘ K
AI Features

Reorder Routes to Make All Paths Lead to the City Zero

Understand how to reorient roads in a directed tree graph so every city can reach the capital, city zero. Learn to find the minimum number of road changes needed, applying graph traversal and problem analysis skills for efficient problem solving.

Statement

There are n cities labeled from 00 to n1n - 1, connected by n1n - 1 roads, so there is only one route between any two cities. This road network forms a tree structure.

Last year, the Ministry of transport made all roads one-way due to their narrow width. These roads are represented as connections, where each entry connections[i] =[ai,bi]= [a_i, b_i] ...