i am getting WA on Maximum distributed tree and i can’t find the error, please help!

https://codeforces.com/contest/1401/submission/90690640

approach:-

my approach is to for each edge calculate the how frequently it is traveled and store it in path_freq and then sort path_freq in decreasing order, and also sort the factors array in decreasing order, now just kept multiplying the greatest factor with greatest path_freq and added them all for the ans.