Write a program that will determine the diameter of a graph after computing the distance between each pair of vertices. The distance is the length of a shortest path from one vertex to another (if there is not path connecting two vertices, then the distance between them is infinity). The diameter is the maximum distance between any pair of vertices in the graph. Note: The diameter of a disconnected graph is infinity. Input will be the number of vertices in the graph (allow for a maximum of fifteen) and an adjacency list; output will be a list of vertex pairs, their distances, and then the diameter of the graph. Input should look something like:
How many vertices in the graph?
Output should look something like:
>> 5
Using the form "a,b", enter the endpoints
of each edge. Type -1 to quit.
>> 1,2
>> 2,3
>> 3,4
>> 4,5
>> -1
The diameter of the graph is 4.
Vertex Pair
Distance
(1,2)
1
(1,3)
2
(1,4)
3
(1,5)
4
(2,3)
1
(2,4)
2
(2,5)
3
(3,4)
1
(3,5)
2
(4,5)
1
If there is not a path connecting two vertices, you should output a distance of "inf". Similarly, if the graph is disconnected, you should output a diameter of "inf". You should run your program on three different data sets: