Doubts in dsa series

doubt1 - https://www.codechef.com/LRNDSA09/problems/CHEFINV - i am using merge sort tree. I tried stress testing my code still couldnt find out why WA.

my code - https://www.codechef.com/viewsolution/37278368

doubt2 - https://www.codechef.com/LRNDSA11/problems/PAIRCLST - my code worked basically dijikstra from all special vertices and return as soon as top of priority_queue > global min - but why did it work whithin time limit??