[SOLVED] CSE208-Offline on Single Source Shortest Path

30.00 $

Category:

Description

Rate this product

In this assignment, you need to implement the Dijkstra and Bellman Ford algorithms to solve the Single Source Shortest Path problem.

 

Input/Output:

You will take input from an input file and give  output to an output file.

 

Input Format:

The graph is directed​ .​

 

The first line has two space-separated integers N​ and M​ ​, the number of nodes and edges in the graph.

 

In the next M​   lines, there will be three space-separated integers u​ ​, v, and ​w denoting an edge where u​ and v​ denote the starting and ending nodes and w denotes the weight of the directed edge.

 

You need to find the distance​ and path​ between the source and destination which will be given in the next line as two space separated integers S​ ​ and D​ ​, the source and destination.

 

Output Format:

In the first line of the output file, you need to print the distance between the source and the destination as a single integer.

 

In the next line, you need to print the path between the source and the destination separating the nodes with “->​ ”.​

 

For Bellman Ford algorithm, you need to detect negative weight cycles as well.

 

See the sample I/O for further clarification.

 

 

Constraints: 

1 < N ≤ 1000

1 < MN * (N − 1) / 2

0 ≤  u, v < N

0 ≤  S, D < N

− 100000 ≤ w ≤ 100000(for Dijkstra, consider |w|)