Why does this code get accepted 55539853 and this does not 55539543?

I believe the time complexity of 1st submission is O(k(n+m)) for k bfs and then O(nklog(k)) for sorting each node.

Can someone tell the complexity of the second code because of which it is failing.

For getting s smallest element I am using slog(s) complexity in bfs in 2nd submission.

Hi community help.

your accepted solutions runs in 1.7 second, which is close to the time limit, so sort vector is faster than popping from priority queue one by one, and therefore you get TLE?

Also, please learn to ask question instead of just posting codes. You can say like: solution 1 uses priority_queue and popping one by one while solution uses vector and sorting it. This will reduce the time taken for people to help you and therefore it will be more likely for someone to help.

But ain't it the same thing. Sorting n elements O(nlog(n)) Popping priority queue O(log(n)) for 1 element so O(nlog(n)) for n elements??

Yes, it is the same in terms of time complexity. But having the same time complexity does not imply that the code is equally fast. For instance, sorting the code 1 time is O(nlog(n)), but sorting it twice is also O(nlog(n)), but is the performance of both code going to be the same?