Shortest path finding algorithm