• + 0 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:
    • 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