public IList <DirectedEdge> [] PathTo(int v) { var verticesToCover = new Stack <int>(); verticesToCover.Push(v); distTo[v] = 0; while (verticesToCover.Count > 0) { var v1 = verticesToCover.Pop(); var adjacentEdgeList = graph.Adj(v1); foreach (var edge in adjacentEdgeList) { //if(marked[edge.To]) continue; if (distTo[edge.To] > (distTo[v1] + edge.Weight)) { distTo[edge.To] = distTo[v1] + edge.Weight; marked[edge.To] = true; hasPath[edge.To] = true; verticesToCover.Push(edge.To); foreach (var item in listOfEdges[v1]) { listOfEdges[edge.To].Add(item); } if (!listOfEdges[edge.To].Contains(edge)) { listOfEdges[edge.To].Add(edge); } } } } return(listOfEdges); }
public IList <DirectedEdge> [] PathTo(int v) { verticesToCover = new IndexedPriorityQueue <DirectedEdge>(graph.VerticesCount); verticesToCover.Add(v, new DirectedEdge(0, 0, 0.0)); distTo[v] = 0; while (!verticesToCover.IsEmpty()) { var v1 = verticesToCover.DeleteMin(); var adjacentEdgeList = graph.Adj(v1.Key); foreach (var edge in adjacentEdgeList) { //if(marked[edge.To]) continue; if (distTo[edge.To] > (distTo[v1.Key] + edge.Weight)) { distTo[edge.To] = distTo[v1.Key] + edge.Weight; marked[edge.To] = true; hasPath[edge.To] = true; verticesToCover.Add(edge.To, edge); foreach (var item in listOfEdges[v1.Key]) { listOfEdges[edge.To].Add(item); } if (!listOfEdges[edge.To].Contains(edge)) { listOfEdges[edge.To].Add(edge); } } } } return(listOfEdges); }
public void Dfs(int i) { var adjEdges = graph.Adj(i); foreach (var edge in adjEdges) { //Console.WriteLine(string.Join(',', isMarked)); if (!isMarked[edge.To]) { isMarked[edge.To] = true; Dfs(edge.To); postOrder.Enqueue(edge.To); } } }