http://mirror.codeforces.com/problemset/problem/543/D
I did not understand the editorial so I wrote a solution of my own. But I don't understand the tricky cases where it fails. Here is my submission ID 11679268 . My logic is simple:
Do DFS with "1" as root , store results in dp[i]
result[1]=dp[1]
result[i]=(1 + result[parent_of_i]/(dp[i]+1)) * dp[i] % mod;
Where is the logic wrong? I couldn't figure it out.