DFS(G)
for each vertex u in G.V
u.color = white
u.pi = NIL
time = 0
let A be a stack
for each vertex u in G.V
if u.color == white
A.push(u)
while A is not empty
x = A.top()
flag = 0
for each v in G:Adj[x]
if v.color == white//遇到堆栈顶端元素相邻的节点有白色的都入栈
flag = 1
time = time + 1
v.d = time
v.pi = x
v.color = gray
A.push(v)
if flag == 0//如果栈顶端节点所有相邻节点都不是白色【均被标记为灰色或者黑色】则出栈
y = A.pop()
y.color = black
time = time + 1
y.f = time