Question: In C++ The Bellman-Ford Algorithm In this assignment, you are asked to implement the Bellman-Ford Algorithm which solves the single-source shortest-paths problem. Specifically, you are

In C++

In C++ The Bellman-Ford Algorithm In this assignment, you are asked to

The Bellman-Ford Algorithm In this assignment, you are asked to implement the Bellman-Ford Algorithm which solves the single-source shortest-paths problem. Specifically, you are given as input a directed graph G = (V, E) with weight w(u, v) on each edge (u, v) E along with a source vertex s V. Edges may have negative weights. Input The input has the following format. There are two integers on the first line. The first integer represents the number of vertices, IV. The second integer is the number of edges, TEL. Vertices are indexed by 0, 1,..., IV-1. Each of the following |Elines has three integers u, v, w(u, v), which represent an edge (u, v) with weight wu, v). Vertex 0 is the source vertex. Output The output falls into two possible cases Case (i): There is no negative-weight cycle reachable from s. In this case, you must output TRUE on the first line, followed by the shortest distance from s to each vertex in the graph. More precisely, you must output TRUE, (0.0), (0.1), ..., (0.VI - 1), one per line. Recall that 8(u, v) denotes the shortest distance from u to v. If a vertex v is not reachable, output INFINITY in place of 8(0, v). Case (ii): There is a negative-weight cycle reachable from 8. You must output FALSE. Examples of input and output Input 1 6 10 016 1 2 5 1 3 -4 1 48 2 1-2 302 3 2 7 3 4 9 407 5 2 5 Output 1 TRUE 11 INFINITY Input 2 6 11 0 1 6 1 2 5 1 3-4 -ON 35 -14 407 5 2 5 Output 2 FALSE Note that every line is followed by an enter key

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!