Hello…
I am upsolving this question from codeforces…
https://codeforces.com/contest/1466/problem/D
My logic is first i store the degree of each node and also stored weighted sum of vertices for each pair of node…
I sorted this vector based on first value in descending order…
Now after printing the sum…
I iterated for n-2 times and each time i check the degree of the pair of nodes if it is greater than 1 then i add the value of each vertices to sum and decreased the degree of each pair of node…
This is my code…
Please check this…
https://codeforces.com/contest/1466/submission/103012657
Why it is showing wrong answer…
Thanks