I'm having trouble using Dijkstra's algorithm when given a text file in this format.
The first line represents the number of vertexes. Should I store this value as a 2-Dimensional Array?
I was thinking that I could have the second part of the 2D array be the actual value each vertex holds.
For example vertex 3 holds 78. Vertex 4 holds 87... etc.
The problem I run into is having to store the edges.
1 4 98
Where 1 is vertex 1, 4 is vertex 4, and the distance between them is 98. How would I store this value of 98?
I'm just stumped here, any advice would be greatly appreciated.
Below is the input
Number of Vertexes
Number of Edges
Vertex NumValue
Vertex Vertex NumValue
Where if there are two vertexes, the NumValue that comes after is the Distance between the two.
Input
5
7
3 78
4 87
5 98
1 4 98
5 4 45
1 5 140
4 3 87
2 5 150
3 5 109
3 2 73
Output
388