// recorrido en profundidad desde v void DepthFirstPaths::dfs(Grafo const& G, size_t v) { marked[v] = true; for (auto w : G.adj(v)) { if (!marked[w]) { edgeTo[w] = v; dfs(G, w); } } }
void DepthFirstSearch::dfs(Grafo const& G, size_t v) { ++_count; _marked[v] = true; for (auto w : G.adj(v)) { if (!_marked[w]) { dfs(G, w); } } }
// recorrido en profundidad de la componente de v void ComponentesConexas::dfs(Grafo const& G, size_t v) { marked[v] = true; _id[v] = _count; ++_size[_count]; for (auto w : G.adj(v)) { if (!marked[w]) { dfs(G, w); } } }
void BreadthFirstPaths::bfs(Grafo const& G, size_t s) { std::queue<size_t> q; distTo[s] = 0; marked[s] = true; q.push(s); while (!q.empty()) { auto v = q.front(); q.pop(); for (auto w : G.adj(v)) { if (!marked[w]) { edgeTo[w] = v; distTo[w] = distTo[v] + 1; marked[w] = true; q.push(w); } } } }