Implementation of the Bellman-Ford algorithm to compute shortest paths from a source node, and return [-1] if a negative weight cycle is detected.
{
"V": 5,
"edges": [
[
1,
3,
2
],
[
4,
3,
-1
],
[
2,
4,
1
],
[
1,
2,
1
],
[
0,
1,
5
]
],
"S": 0
}[
0,
5,
6,
6,
7
]{
"V": 3,
"edges": [
[
0,
1,
5
],
[
1,
2,
-2
],
[
2,
0,
-5
]
],
"S": 0
}[
-1
]{
"V": 4,
"edges": [
[
0,
1,
4
],
[
0,
2,
8
],
[
1,
2,
2
],
[
2,
3,
3
]
],
"S": 0
}[
0,
4,
6,
9
]Sign in to Run Code and Submit