Skip to content

Commit

Permalink
Merge pull request #39 from cp-sapienza/bellman_ford_edge_case
Browse files Browse the repository at this point in the history
fix edge case of a 1 node graph with a negative loop
  • Loading branch information
podd0 authored Oct 30, 2023
2 parents ae02604 + 9604392 commit b0285be
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion source/bellman_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ vector<ll> bellman_ford(vector<array<int, 3>>& edges, int v, int src) {
}
}

for (int i = 0; i < v - 1 && relaxed; ++i) {
for (int i = 0; i < v && relaxed; ++i) {
relaxed = false;
for (auto [start, end, weight] : edges) {
if (dist[start] == -INF || (dist[start] != INF && dist[start] + weight < dist[end])) {
Expand Down

0 comments on commit b0285be

Please sign in to comment.