My Solution: https://codeforces.com/contest/580/submission/83913055
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 : https://ideone.com/ZsJJBa , i added some comments but you can ask if you had any query further.
Thank you so much, i understood your solution and implemented it successfully.