My code is passing all the sample input but not the test cases. could you point out the mistake?
Hostel Visit question test cases
Hi Ankit
Here’s the issue with your code.
While pushing an element and popping one out from the heap you are not comparing whether the new element has a lesser distance value than the top element of the heap. You are simply pushing them anyways
Try this testcase
20 10
1 -5 -4
1 -2 -6
1 8 9
1 -6 2
1 7 -5
1 2 9
1 0 5
1 3 3
1 3 -8
1 2 10
1 4 3
1 8 -4
2
1 6 8
2
2
2
1 4 -2
1 0 -3
2
Expected Output :
85
85
85
85
74
Your Output :
85
100
100
100
74
Try comparing the new element with pq.top() .
Also change the return type of dist () to long long int as distance is very likely to exceed the range of int.
Replace all occurrences of int with long long int …except for the int main( ) ofcourse.
Okay thanks. It worked
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.