Problem Link: CodeChef: Practical coding for everyone
Can somebody please explain the optimal approach to solve this problem?
Parallel bfs. Start a bfs from every treasure together. And keep only one found checker array for all bfs. If you find it in the first iteration, distance is 1,and so on. Make sure your queue is sorted by distance. Basically instead of pushing a single node in queue, push all the treasures in queue at the start.
Edit: yes it’s bfs.
2 Likes
read the edit ,thanks
1 Like