We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The first thing to do is tranversing the tree to imagine how the tree is. Next, we notice that in the tree we've created above:
if u - v guess is correct. It means u is parent[v]. That guess is also correct for all nodes (except v's children as it will make the tree reverse)
if u - v guess is incorrect. It means v is parent[u]. That guess is only correct when root is u or u's children
=> To count how many win cases, i suggest to use dfs to reuse the number of win cases of parent nodes
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Story of a Tree
You are viewing a single comment's thread. Return to all comments →
Hint:
The first thing to do is tranversing the tree to imagine how the tree is. Next, we notice that in the tree we've created above: