recursive shortest path works