Need help in graph problem

My Solution:
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 : , 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.