Final Challenge #1
Lesson 8 of 9 in Coddy's Bellman-Ford Algorithm - Graph Algorithms course.
Challenge
MediumBellman-Ford's superpower is spotting negative cycles.
Write a function named hasNegativeCycle that takes n and the flat edges array (triples, directed) and returns 1 if the graph contains a negative-weight cycle, or 0 otherwise.
Hint: start every distance at 0, relax all edges n - 1 times, then do one more pass. If any edge can still be relaxed, a negative cycle exists.
Try it yourself
#include <stdlib.h>
int hasNegativeCycle(int n, int* edges, int edges_size) {
// Write code here
return -1;
}