Dijkstra first node visited


I’m implementing a Dijkstra program in C++ and I’m having some problems, let me explain:

For the moment I’ve been following this code:

This code prints the full path from the source to all other vertexs.
I’m using an array int parent[num_vertexs]; to store the path. But the problem is that I don’t want the full path, only the FIRST vertex visited.

How can I get only the first node visited? Is there any way to print only the first node of the parent array for each node?

Thank you very much for your time.


Yes, there’s a way. If you edit the relevant function into your question, we’ll show you how to change it. (We don’t like link-dependent questions here.)



Add a Comment