Question: You are asked to Create a C + + program that uses Graphs to find the shortest paths between vertices in graphs. We will use
You are asked to Create a C program that uses Graphs to find the shortest paths between vertices in graphs. We will use the classic Dijkstras algorithm to find the shortest distance from a starting vertex to every other vertex in a graph. We will use this to find the distance between every pair of vertices in a graph and display the results. As an example, consider a weighted graph: This graph can be represented in an adjacency matrix as:
Input files
The input files contain several lines with integer values, separated by spaces as needed. All input files are well formed with valid values. There is no need for exception handling on the inputs and all files follow the same format.
The first line provides the number of vertices in the graph. This value will always be positive and there will always be multiple rows containing the edges in the graph. There will never be a degenerate graph that is empty or contains no edges.
The next lines in the file contain the values for each edge in the graph. These lines contain the fromvertex number, the tovertex number and the weight of the edge. These will be positive integer values, well always appear in groups of three, and each of the numbers is separated by a space.
For example, the inputtxt contains:
This corresponds to the graph shown above. We can compute the shortest distance from any vertex to any other vertex. Suppose we pick vertex as the starting point, the distance to every other vertex is then:
Continuing, we can compute the shortest distance to all vertices starting from vertex and so on
Output files
Output the minimum distance through the graph to each other vertex, starting from each vertex in order. Output the results for each starting vertex, one per line.
Output the minimum distance one each line with spaces allowed for each number and a space before and after each value.
For example, the anstxt contains:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
