Background information
The standard implementation of DFS you will often see in an algorithms textbook or implementation involves arrays for the color (really just a processing state), the discovery time, and the finish time of each node.
Here is a simple source traversal (not global) DFS example in pseudocode for a graph G and source v. Assume colors , discovered , and finished are already allocated for the |V| vertices, colors has every element initialized to white, and timer is zero initialized.
DFS(G, v) discovered[v] = timer++
// Mark this node as "currently in traversal" colors[v] = grey
for u in G.Adjacency[v] // If the node state is "unseen" then // this is a tree edge if colors[u] == white DFS(G, u)
// Once we have gone over every vertex, set // the node state to "processed" and record // the finish time.…