Python

C

Java

Python result:

C result:

Java result:

The Bellman-Ford Algorithm starting from vertex D:

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

D, Distance: 0

D->E, Distance: 3

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

D, Distance: 0

D->E, Distance: 3

The Bellman-Ford Algorithm starting from vertex D:

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

D, Distance: 0

D->E, Distance: 3

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

D, Distance: 0

D->E, Distance: 3

The Bellman-Ford Algorithm starting from vertex D:

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

No path from D to D, Distance: 0

D->E, Distance: 3

Relaxing edge D->A, Updated distance to A: 4

Relaxing edge D->C, Updated distance to C: 7

Relaxing edge D->E, Updated distance to E: 3

Relaxing edge E->B, Updated distance to B: 5

Relaxing edge E->C, Updated distance to C: 6

Relaxing edge B->C, Updated distance to C: 1

Relaxing edge C->A, Updated distance to A: -2

D->E->B->C->A, Distance: -2

D->E->B, Distance: 5

D->E->B->C, Distance: 1

No path from D to D, Distance: 0

D->E, Distance: 3