https://sapphireengine.com/@/blgws

I have tried many test cases but my answer is still wrong. kindly help me where I am wrong

Hey Ankit! You have done a small mistake in your bfs function. You have taken the size of distance array as [horse+1] that is wrong, For Example- If there are 3 horses and final checkpoint is 10, so your distance array has only 3+1 size and the in if(!visited[i]) loop you are measuring distance of all the nodes that are connected to 10, so it may contain 8th,9th node and you are doing distance[8]= distance [10]+1, but you dont have distance[9] and distance[10].

I have submitted your code with these changes and it is running correctly. You can check this in my profile aayush_273.

Thankyou.

1 Like