C. Linova and Kingdom

Problem from codeforces round 635(Div 2)
Problem link:https://codeforces.com/contest/1337/problem/C

My submission:Submission #79046378 - Codeforces

Verdict: wrong answer.

Can some one please help me.
Thanks in advance :slight_smile:

I summed up the contribution of (n-k) touristplaces to the ans i.e., if at all I choose a node that act as tourist place i added(sizeofsubtree rooted at this particular node excluding itself - depth of node) to ans.And at the last printed it out. Isn’t my assumption right?

Yeah Accepted.I just changed the data type of ans from int to long long.

you have already sorted in descending order so just traverse from i=0 to i<k and sum the values of your asc vector’s value . it will give you AC