Valid Binary Tree Root with Alternating Two-Color Layers

Extending the previous problem, each vertex has a color (black or white). The graph is acyclic, undirected and connected, and every vertex has at most 3 neighbours. Find a root such that: (1) rooted t...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: