//Пошук в глибину(для 5 умови) private void DFScycleForFifth(int u, int endV, List<DataEdge> E, List<DataVertex> V, int[] color, int unavailableEdge, List<int> cycle, Graph graph) { //если u == endV, то эту вершину перекрашивать не нужно, иначе мы в нее не вернемся, а вернуться необходимо if (u != endV) color[u] = 2; else if (cycle.Count >= 2) { cycle.Reverse(); string s = cycle[0].ToString(); for (int i = 1; i < cycle.Count; i++) s += "-" + cycle[i].ToString(); /////////////////////// List<DataVertex> list = new List<DataVertex>();//Додаю вершину в цикл list.Add(V.ElementAt(cycle[0])); for (int i = 1; i < cycle.Count - 1; i++) list.Add(V.ElementAt(cycle[i])); /////////////////////// bool flag = false; //есть ли палиндром для этого цикла графа в List<string> catalogCycles? for (int i = 0; i < catalogCycles.Count; i++) if (catalogCycles[i].ToString() == s) { flag = true; break; } if (!flag) { cycle.Reverse(); list = new List<DataVertex>(); list.Add(V.ElementAt(cycle[0])); for (int i = 1; i < cycle.Count - 1; i++) list.Add(V.ElementAt(cycle[i])); catalogCycles.Add(list); } return; } for (int w = 0; w < E.Count; w++) { var q = graph.OutEdges(V[V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)]); if (w == unavailableEdge || (graph.InEdges(V[V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)]).Count() > 1 || graph.OutEdges(V[V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)]).Count() > 1) && V.FindIndex(x => x.Text == E[w].Target.Text) != endV) continue; if (color[V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)] == 1 && V.FindIndex(0, V.Count, x => x.Text == E[w].Source.Text) == u) { List<int> cycleNEW = new List<int>(cycle); cycleNEW.Add(V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)); DFScycleForFifth(V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text), endV, E, V, color, w, cycleNEW, graph); color[V.FindIndex(0, V.Count, x => x.Text == E[w].Target.Text)] = 1; } } }