private void Dfs(int v, int s) { _marked[v] = true; foreach (int w in _g.Adj(v)) { if (_hasCycle) { break; } if (!_marked[w]) { _pathTo[w] = v; Dfs(w, v); } else if (w != s) { _hasCycle = true; _cycle.Push(w); while (v != w) { _cycle.Push(v); v = _pathTo[v]; } _cycle.Push(w); } } }
public static int Degree(Graph g, int v) { int degree = 0; foreach (var temp in g.Adj(v)) { degree++; } return(degree); }
private void Dfs(int v) { _id[v] = _count; _marked[v] = true; foreach (var w in _g.Adj(v)) { if (!_marked[w]) { Dfs(w); } } }
private void Dfs(int v) { foreach (var w in _g.Adj(v)) { if (!_marked[w]) { _marked[w] = true; _pathTo[w] = v; Dfs(w); } } }
private void DFS(int v, int parent) { visited[v] = true; prev[v] = parent; foreach (int w in G.Adj(v)) { if (!visited[w]) { DFS(w, v); } } }
public void Search(Graph g, int s) { _marks[s] = true; foreach (var temp in g.Adj(s)) { if (!_marks[s]) { Search(g, temp); } } }
private void DFS(int v, int ccid) { visited[v] = ccid; foreach (int w in G.Adj(v)) { if (visited[w] == -1) { DFS(w, ccid); } } }
public void Dfs(Graph g, int s) { _marks[s] = true; foreach (var temp in g.Adj(s)) { if (!_marks[temp]) { _edgeTo[temp] = s; Dfs(g, temp); } } }
public override void Search(Graph g, int s) { _marks[s] = true; count++; foreach (var temp in g.Adj(s)) { if (!_marks[temp]) { Search(g, temp); } } }
private void DFS(int v) { visited[v] = true; _preOrder.Add(v); foreach (int w in G.Adj(v)) { if (!visited[w]) { DFS(w); } } _postOrder.Add(v); }
private void Dfs(int v) { _marked[v] = true; foreach (var w in _g.Adj(v)) { if (!_marked[w]) { _color[w] = !_color[v]; Dfs(w); } else if (_color[w] == _color[v]) { _isBipartite = false; } } }
public void Search(Graph g, int s) { _pre.Enqueue(s); _marks[s] = true; foreach (var temp in g.Adj(s)) { if (!_marks[temp]) { Search(g, temp); } } _post.Enqueue(s); _reversePost.Push(s); }
public static int NumberOfSelfLoops(Graph g) { int count = 0; for (int v = 0; v < g.Vertice(); v++) { foreach (var temp in g.Adj(v)) { if (v == temp) { count++; } } } return(count); }
private bool DFS(int v, int parent) { visited[v] = true; foreach (int w in G.Adj(v)) { if (!visited[w]) { if (DFS(w, v)) { return(true); } } else if (w != parent) { return(true); } } return(false); }
private void Bfs() { Queue <int> queue = new Queue <int>(); queue.Enqueue(_s); while (queue.Count > 0) { int q = queue.Dequeue(); foreach (var w in _g.Adj(q)) { if (!_marked[w]) { _pathTo[w] = q; queue.Enqueue(w); _marked[w] = true; } } } }
private bool DFS(int v, int color) { visited[v] = true; colors[v] = color; foreach (int w in G.Adj(v)) { if (!visited[w]) { if (!DFS(w, 1 - color)) { return(false); } } else if (colors[v] == colors[w]) { return(false); } } return(true); }
private bool DFS(int v, int parent) { visited[v] = true; prev[v] = parent; if (v == t) { return(true); } foreach (int w in G.Adj(v)) { if (!visited[w]) { if (DFS(w, v)) { return(true); } } } return(false); }
private void BFS(int v) { Queue <int> queue = new Queue <int>(); visited[v] = true; queue.Enqueue(v); while (queue.Count > 0) { int frnt = queue.Dequeue(); _order.Add(frnt); foreach (int w in G.Adj(frnt)) { if (!visited[w]) { visited[w] = true; queue.Enqueue(w); } } } }
private void Dfs(Graph g, int s) { Queue <int> queue = new Queue <int>(); _marked[s] = true; queue.Enqueue(s); while (queue.Count != 0) { int v = queue.Dequeue(); foreach (var temp in g.Adj(v)) { if (!_marked[temp]) { queue.Enqueue(temp); _marked[temp] = true; _edgeTo[temp] = v; } } } }