Question 2:
Question 2: (4 marks)
Write a program to build an undirected graph by giving edge list.
Your task is finding and one shortest path from startVertex to end Vertex.
The input: are stored in the dijkstra_input.txt text file:
The first line contains 4 positive integers N, M, s and e that separated by one space:
o N (1 ≤ N ≤20) is the number of vertex of undirected graph.
。 M (N-1 ≤ M ≤190) is the number of edge of undirected graph.
3 of 4
Paper No: 1
os (0 ≤s≤N-1) is the start vertex.
o e (0 ≤e≤N-1, se) is the end vertex.
● The next M line, each line containing 3 positive integers u and v and d that separated by one space:
ou (0 ≤u<N) the start vertex of the edge (u, v).
ov (0 ≤v<N, vu) the end vertex of the edge (u, v).
od (0 ≤d≤ 10%) the value of the edge (u, v).
The output: the results need to be saved to the dijkstra_output.txt text file:
The first line contains the distance of shortest path.
The second line contains the list of vertices of the shortest path from s to e. Each vertex separated
FUOy one comma.