Imagine Alice has a beautiful undirected tree with n nodes labeled from 0 to n-1. The tree is represented as a 2D array edges where each edges[i] = [ai, bi] indicates there's an edge connecting nodes ai and bi.
Alice wants Bob to discover the root of her tree. She allows Bob to make educated guesses about parent-child relationships. In each guess, Bob:
- Chooses two connected nodes
uandv(where an edge exists between them) - Guesses that
uis the parent ofvin the rooted tree
Bob's guesses are represented by array guesses where guesses[j] = [uj, vj] means Bob thinks uj is the parent of vj.
Alice, being busy, doesn't check each guess individually. Instead, she simply tells Bob that at least k of his guesses are correct.
Your mission: Given the tree structure (edges), Bob's guesses (guesses), and the minimum correct guesses (k), determine how many different nodes could potentially be the root of Alice's tree.
Input & Output
Constraints
- n == edges.length + 1
- 2 β€ n β€ 105
- 1 β€ guesses.length β€ 105
- 0 β€ ai, bi < n
- ai != bi
- edges represents a valid tree
- guesses[i] = [ui, vi] where there exists an edge between ui and vi
- 0 β€ k β€ guesses.length