Below is the general code for DFS with logic for marking back edges and tree edges. My doubt is that back edges from a vertex go back and point to an ancestor and those which point to the parent are not back edges (lets assume undirected graph). In an undirected graph we have an edge back and forth between 2 vertices $x$ and $y$. So after visiting $x$ when I process $y$, $y$ has $x$ as an adjacent vertex, but as its already visited, the code will mark it as a back edge. Am I right in saying that? Should we add any extra logic to avoid this, in case my assumption is valid?
DFS(G)
for v in vertices[G] do
color[v] = white
parent[v]= nil
time = 0
for v in vertices[G] do
if color[v] = white then
DFS-Visit(v)
Induce a depth-first tree on a graph starting at $v$.
DFS-Visit(v)
color[v]=gray
time=time + 1
discovery[v]=time
for a in Adj[v] do
if color[a] = white then
parent[a] = v
DFS-Visit(a)<br>
v->a is a tree edge
elseif color[a] = grey then
v->a is a back edge
color[v] = black
time = time + 1
white means unexplored
, gray means frontier
, black means `processed'