It will work, just make get_path take 3 parameters (add Path also as the 3rd).
Also make sure you take into account that edge(A, B, X) also means edge(B, A, X). So when you implement the algorithm and your current node is Z, find a neighbor either by calling edge(Z, Neighbor, D) or by calling...