Exemplo n.º 1
0
bool GraphOperations::_euler_tour(const Graph &graph,
								  vertex_t vertex,
								  component_t& path,
								  std::set<size_t>& visited)
{
	if (visited.size() == graph.number_of_edges())
	{
		path.push_back(vertex);
		
		return true;
	}
	
	for (const auto& adjacent : graph.adjacent(vertex))
	{
		if (! visited.count(adjacent.second))
		{
			auto copy = visited;
			
			copy.insert(adjacent.second);
			
			if (_euler_tour(graph, adjacent.first, path, copy))
			{
				path.push_back(vertex);
				
				return true;
			}
		}
	}
	
	return false;
}
Exemplo n.º 2
0
void ConnectedComponents::_dfs(const Graph& graph,
							   vertex_t vertex,
							   bitset_t& visited,
							   component_t& component,
							   id_t id)
{
	visited[vertex] = true;
	
	_ids[vertex] = id;
	
	component.push_back(vertex);
	
	for (auto adjacent : graph.adjacent(vertex))
	{
		if (! visited[adjacent.first])
		{
			 _dfs(graph, adjacent.first, visited, component, id);
		}
	}
}