Getting wrong answer

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

Hey @ashishnnnnn
For this tc its not working
Do a dry run u will understand the fault in ur logic

1
6
1 10 10 0 10 1
1 2
1 3
2 4
3 5
5 6 

Correct answer  : 32 42 52 62 63
your answer       : 32 52 52 53 63

Got it…
I am not ensuring the connected Component term…

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.