Edge(Edge&&) =
default;
32Edge& operator=(Edge&&) =
default;
33Edge(Edge
const&) =
default;
34Edge& operator=(Edge
const&) =
default;
41 Edge(
unsigned intsource,
unsigned intdestination)
42: src(source), dest(destination) {}
45usingAdjList = std::map<unsigned int, std::vector<unsigned int>>;
57Graph() : m_adjList({}) {}
59Graph(Graph&&) =
default;
60Graph& operator=(Graph&&) =
default;
61Graph(Graph
const&) =
default;
62Graph& operator=(Graph
const&) =
default;
69 Graph(
unsigned intvertices, AdjList adjList)
70: m_vertices(vertices), m_adjList(std::move(adjList)) {}
77 Graph(
unsigned intvertices, AdjList&& adjList)
78: m_vertices(vertices), m_adjList(std::move(adjList)) {}
89 Graph(
unsigned intvertices, std::vector<Edge>
const& edges)
90: m_vertices(vertices) {
91 for(
auto const& edge : edges) {
92 if(edge.src >= vertices || edge.dest >= vertices) {
93 throwstd::range_error(
94 "Either src or dest of edge out of range");
96m_adjList[edge.src].emplace_back(edge.dest);
104std::remove_reference<AdjList>::type
const&
getAdjList()
const{
126 if(edge.src >= m_vertices || edge.dest >= m_vertices) {
127 throwstd::range_error(
"Either src or dest of edge out of range");
129m_adjList[edge.src].emplace_back(edge.dest);
137 void addEdge(
unsigned intsource,
unsigned intdestination) {
138 if(source >= m_vertices || destination >= m_vertices) {
139 throwstd::range_error(
140 "Either source or destination of edge out of range");
142m_adjList[source].emplace_back(destination);
146 unsigned intm_vertices = 0;
161 enumnodeStates : uint8_t { not_visited = 0, in_stack, visited };
172std::vector<nodeStates>* state,
173 unsigned int node) {
175(*state)[
node] = in_stack;
179 auto constit = adjList.find(
node);
180 if(it != adjList.end()) {
181 for(
autochild : it->second) {
184 autostate_of_child = (*state)[child];
185 if(state_of_child == not_visited) {
189}
else if(state_of_child == in_stack) {
200(*state)[
node] = visited;
214 autovertices =
graph.getVertices();
223std::vector<nodeStates> state(vertices, not_visited);
226 for(
unsigned int node= 0;
node< vertices;
node++) {
230 if(state[
node] == not_visited) {
251 autographAjdList =
graph.getAdjList();
252 autovertices =
graph.getVertices();
254std::vector<unsigned int> indegree(vertices, 0);
256 for(
auto const&
list: graphAjdList) {
257 autochildren =
list.second;
258 for(
auto const& child : children) {
263std::queue<unsigned int> can_be_solved;
264 for(
unsigned int node= 0;
node< vertices;
node++) {
267 if(!indegree[
node]) {
268can_be_solved.emplace(
node);
273 autoremain = vertices;
275 while(!can_be_solved.empty()) {
276 autosolved = can_be_solved.front();
283 autoit = graphAjdList.find(solved);
284 if(it != graphAjdList.end()) {
285 for(
autochild : it->second) {
287 if(--indegree[child] == 0) {
290can_be_solved.emplace(child);
298 return!(remain == 0);
307 Graph g(7, std::vector<Edge>{{0, 1}, {1, 2}, {2, 0}, {2, 5}, {3, 5}});
static bool isCyclicDFSHelper(AdjList const &adjList, std::vector< nodeStates > *state, unsigned int node)
static bool isCyclicBFS(Graph const &graph)
static bool isCyclicDFS(Graph const &graph)
Edge(unsigned int source, unsigned int destination)
std::remove_reference< AdjList >::type const & getAdjList() const
Graph(unsigned int vertices, AdjList &&adjList)
unsigned int getVertices() const
Graph(unsigned int vertices, std::vector< Edge > const &edges)
void addVertices(unsigned int num=1)
void addEdge(unsigned int source, unsigned int destination)
Graph(unsigned int vertices, AdjList adjList)
void addEdge(Edge const &edge)
double g(double x)
Another test function.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4