NeetCode #571LC-1466MediumGraphs
← Back to All Problems

#571 · #1466 · Reorder Routes to Make All Paths Lead to the City Zero(重新规划路线)

📌 Problem Statement & Constraints

There are n cities numbered 0..n-1 and n - 1 directed roads forming a tree. connections[i] = [a, b] means the road goes from a to b. Reorient some roads so that every city can reach city 0. Return the minimum number of roads to reorient. Constraints: 2 <= n <= 5 * 10^4, connections.length == n - 1.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!