// Devuelve un camino desde el origen a v (vacío si no están conectados). Path DepthFirstPaths::pathTo(size_t v) const { Path path; if (!hasPathTo(v)) return path; for (auto x = v; x != s; x = edgeTo[x]) path.push_front(x); path.push_front(s); return path; }
std::deque<DirectedEdge> *Djikstra::pathTo(int v){ if(!hasPathTo(v)) return 0; std::deque<DirectedEdge> *path = new std::deque<DirectedEdge>(); for(DirectedEdge e = edgeTo[v]; e.from() || e.to() || e.Getweight(); e =edgeTo[e.from()]) path->push_front(e); return path; }
std::deque<int> DepthFirstSearch::pathTo(int t){ std::deque<int> path; if(!hasPathTo(t)) return path; for(int x = t; x != src; x = edgeTo[x]){ path.push_front(x); } path.push_front(src); return path; }
// 返回从起点s到v的路径 // 注意:返回的集合是倒序的即从v到s,如果需要从s到v可以用栈或者 // 使用vector的反向迭代器 std::vector<int> pathTo(const int v) { std::vector<int> path; if(!hasPathTo(v)) return path; for(int x = v; x != s; x = edgeTo[x]) path.push_back(x); path.push_back(s); return path; }
std::deque<DirectedEdge> *BellmanFord::pathTo(int v){ if(!hasPathTo(v)) return 0; std::deque<DirectedEdge> *path = new std::deque<DirectedEdge>(); for(DirectedEdge e = edgeTo[v];e.from() || e.to() || e.Getweight(); e=edgeTo[e.from()] ){ int w = e.from(); w++;w--; path->push_front(e); } return path; }
BellmanFordSP::PathToStack BellmanFordSP::pathTo(int v) const { BellmanFordSP::PathToStack retStack; if (!hasPathTo(v)) return retStack; int i = v; for (; edges[i].getWeight() != 0.0; i = edges[i].from()) { retStack.push(i); } retStack.push(i); return retStack; }
std::vector<int> DepthFirstPaths::pathTo(const std::size_t &v) { if(!hasPathTo(v)) throw "No Path"; std::stack<int> path; std::vector<int> p; for(std::size_t x = v; x != s; x = edgeTo[x]) { path.push(x); } path.push(s); while(!path.empty()) { p.push_back(path.top()); path.pop(); } return p; }
double BellmanFordSP::distTo(int v) const { if (!hasPathTo(v)) return std::numeric_limits<double>::max(); return distances[v]; }