Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DFS(G=(V,E))
- // π[u] – Parent of u in the DFS tree
- 1 for each vertex u ∈ V {
- 2 color[u] ← WHITE
- 3 π[u]← NULL
- 4 time ← 0}
- 5 for each vertex u ∈ V {
- 6 if color[u] = WHITE
- 7 DFS-VISIT(u)}
- DFS-Visit(u)
- // white vertex u has just been discovered
- 1 color[u] ← GRAY
- 2 time ← time+1
- 3 d[u] ← time
- 4 for each v ∈ Adj[u] { // going over all edges {u, v}
- 5 if color[v] = WHITE {
- 6 π[v] ← u
- 7 DFS-VISIT(v) }
- 8 else if color[v] = GRAY // there is a cycle in the graph
- 9 CheckIfOddCycle (u, v);
- 10 color[u] ← BLACK
- // change the color of vertex u to black as we finished going over it
- 11 f[u] ← time ← time+1
- CheckIfOddCycle(u, v)
- 1 int count ← 1;
- 2 vertex p = u;
- 3 while (p! = v) {
- 4 p ← π[p]
- 5 count++ }
- 6 if count is an odd number {
- 7 S.O.P (“The graph is not bipartite!”);
- 8 stop the search, as the result is now concluded!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement