static void Main(string[] args) { DataWeightedGraphs graphs = new DataWeightedGraphs("Shortest Cycle Through a Given Edge.txt"); graphs.Print(); Console.WriteLine("Finish"); Console.ReadKey(); /* int[] r = ShortestCycleThroughAGivenEdge(graphs); Utils.PrintArrayToFile(r); Console.WriteLine(); Console.WriteLine("Finish"); Console.ReadKey(); */ }
private static int[] ShortestCycleThroughAGivenEdge(DataWeightedGraphs graphs) { int[] r = new int[graphs._count]; int[] dist; for(int i = 0; i < graphs._count; i++) { int start = graphs._GraphsWeithedAdj[i].start; int finish = graphs._GraphsWeithedAdj[i].finish; int weight = graphs._GraphsWeithedAdj[i].weight; dist = BFS_Dijkstra1(graphs._GraphsWeithedAdj[i], start); if (dist[finish] == -1) { r[i] = dist[finish]; continue; } r[i] = dist[finish] + weight; } return r; }