First of all, I define all distances in the map a positive integer by default.
Just calculate it step by step and return NO SUCH ROUTE
when a node is unreachable.
Both of them are typical search-releated question. Both BFS and DFS works and I choose BFS.
> cd trains
> python3 trains.py
> cd trains
> python3 test.py