10409

 

10171

 

10269

This can be done two ways using floyed-warshall algorithm and also using bfs; Floyed warshall:

BFS:

 

571

 

104

 

423

 

10246

 

523

 

10085

 

821