Back to problems

Find minimum reversals to orient edges away from root

Algorithm · Uber · Medium

A tree with n labeled vertices from 0 to n - 1 is provided as n - 1 directed edges. The list edges contains one entry per edge: edges[i] = [u, v] means the edge is currently directed from u to v. If the directions are ignored, these edges form a connected, acyclic graph. You are also given an integer root. Once the tree is rooted at root, each edge must be aligned with the unique path starting at root: it should point from the vertex closer to root to the vertex farther away…

Checking your access…