static void Main(string[] args) { GraphWeithedAdjAlt0 data = new GraphWeithedAdjAlt0("Negative Weight Cycle.txt"); //data.PrintToFile(); //Console.WriteLine(); //Console.WriteLine("Finish!"); //Console.ReadKey(); int[] r = Negative_Weight_Cycle(data); Utils.PrintArray(r); Console.WriteLine(); Console.WriteLine("Finish!"); Console.ReadKey(); }
public static int[] Negative_Weight_Cycle(GraphWeithedAdjAlt0 data) { int[] r = new int[data.Graphs.Length]; for(int i = 0; i < data.Graphs.Length; i++) { for(int j = 0; j < data.Graphs[i].v.Length; j++) { int rr = BellmanFordAlgorithm(data.Graphs[i], j); if (rr == 1) { r[i] = 1; break; } r[i] = -1; } } return r; }