public void CalcPath() { for (int i = 2; i <= _length; i++) { if (i == 2) { var paths = new List <List <int> >(); var edges = _graph.GetEdges(); foreach (var item in edges) { if (item.Start.Key < item.End.Key) { var path = new List <int>() { item.Start.Identifier, item.End.Identifier }; paths.Add(path); } } _lengthPaths[i] = paths; } else { var paths = new List <List <int> >(); var prePaths = _lengthPaths[i - 1]; foreach (var prePath in prePaths) { var startVertex = _graph.GetVertexByKey(prePath[0]); var startEdges = _graph.GetVertexEdge(startVertex); foreach (var startEdge in startEdges) { var endVertex = startEdge.End; if (!prePath.Contains(endVertex.Identifier)) { var path = new List <int>(prePath); path.Insert(0, endVertex.Identifier); paths.Add(path); } } } _lengthPaths[i] = paths; } } }