Need help in graph problem

Problem: Problem - 580C - Codeforces
My Solution: Submission #83913055 - Codeforces
verdict: TLE
I tried all paths from leaves to root and counted how many paths satisfy the given condition.
Need better approach as i did not understood the given editorial.

I had done it with a simple dfs. You can check my dfs function : ZsJJBa - Online IDE & Debugging Tool - Ideone.com , i added some comments but you can ask if you had any query further.

1 Like

Thank you so much, i understood your solution and implemented it successfully.