modified the way to print shortest path