What i did is, did dfs to calculate cost of all nodes untill all were visited and when a leaf was found, inserted it into answer vector. Finally greedily assigned maximum energies people to maximum cost that was possible for them
Hey , in your last loop calculating the answer, your condition is i <N instead of i<X.size() . Because special cities will be less than n.
Here is corrected solution. (I also made int long long) https://www.codechef.com/viewsolution/45075152
It seems my code is correct for problem D - Click Here
But I am getting WA in it, I have also covered the corner case (didn’t consider 1 as the special city).
I ran a DFS and calculated the distances of the leaf nodes(special cities) and then I greedily assigned the special cities to the people.
Can anyone point out the mistake, where I am going wrong?
Thank you brother but I don’t get it what difference it makes by taking capital city also. I mean the problem setters purposefully use these kind of wierd and unnecessary condition to penalize or waste time of users. I really don’t find the need of such unnecessary confusions in problem statements as it teaches nothing