Search
⌘K

Leetcode 2581. Count Number of Possible Root Nodes

Given an undirected tree and a set of directed parent guesses (each guess orients an existing edge u→v), count how many choices of root make at least k guesses true. The core challenge is to evaluate correctness for all possible roots efficiently (n, guesses ≤ 1e5) by computing the count for one root via DFS and then using a rerooting technique to update the count in O(1) per edge.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.