How to write fast solution?

I can solve it by breadth-first search with Execution time:0.218, but how to solve it with Execution time:0.015 or 0.031??? I have no idea about it. Give me please idea or algorithm's name to solve it so fast. thank you!

Re: How to write fast solution?

[code deleted]

his work time 0.31

*Edited by moderator 19.11.2019 23:11*

Re: How to write fast solution?

Posted by

Skeef79 20 Dec 2018 15:37

You can solve fast using BFS))

[code deleted]

work timeL 0.015

*Edited by author 20.12.2018 15:38*

*Edited by moderator 19.11.2019 23:11*