Help required in Path-etic Products

My approach, Find the diameter, applying a dfs with root = one leaf of the diameter. dfs(root,root,1)
ans[u] = 1(1 <= u <= n)
dfs(u,pu,cnt):
____ans[u] *= (all prime divisor of cnt) // for cnt = 12, I’ll multiply 2 * 3 to ans[u]
____for x in a[u]:
________dfs(x,u,cnt + 1)

Reason to do this, by this 2 will occur in every two nodes in a path, 3 will occur in every three nodes in a path and so on. (5,7,11,…)
I got WA, can anyone suggest where I went wrong?
My solution link: CodeChef: Practical coding for everyone
PS: ignore the rec function, that’s a stupidfunction I made

1 Like

@galencolin maybe you can help

Bro I too just asked the same doubt lol

1 Like

Wow, paste the link here, so I can see the solution of OUR problem

https://www.codechef.com/viewsolution/35809953

1 Like

I too wasted a lot of time trying to do the same , if anyone can explain why this fails it would be of great help

1 Like