chefpres chef under pressure

if the chef is in the city where product is present then output will be that city only ?

Come on, it’s written in problem statement…

It is possible that C may equal A, in which case he does not have to travel at all.

1 Like

no, it isn’t necessary that the chef will stay in the present city only, since C is the city satisfying the given conditions, and with the minimum index… so if A sells product P, then it is not necessary that C is equal to A…
Look at this example: if n=3, k=1, b=3, and all the 3 cities sell the same product 1, and the 2 roads are between 3 & 2, and 2 & 1, then the answer of the query 2 1 will be 1.


@gvaibhav21 u are absolutely 100% correct, i appreciate ur clear way of explaining.
@betlista pls note the phrase “may equal”

@gVaibhav21 what should be the ans for 3 1 in the case you mentioned?

I think you are not correct, but let’s discuss this in details after the contest end.

Its clearly mentioned in the question statement, and my AC code gives the aforesaid o/p.

@gvaibhav21 is correct. Notice “If there are several cities with this property, Chef will choose the one with the smallest number.”

I realized, that you are correct :wink:

If you had not taken care of this in your accepted solutions, this might mean weak test cases :wink:

It’s more like I’m not handling it as a special case…

the answer will be 1.