Refactored Dijkstra to print shortest path in a separate function