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 editorial code is painful to look at. This problem is solveable using union find + dfs. Simply merge all consecutive black edges with union find, and then create a graph out of the componenets. Perform a dfs, and for each node i:
Calculate the # of possible triplets if i is part of the triplet
Calculate the # of possible triplets if i is not part of the triplet
Kundu and Tree
You are viewing a single comment's thread. Return to all comments →
The editorial code is painful to look at. This problem is solveable using union find + dfs. Simply merge all consecutive black edges with union find, and then create a graph out of the componenets. Perform a dfs, and for each node i:
Code: https://www.hackerrank.com/challenges/kundu-and-tree/submissions/code/50715137