#__author__=lx
#__date__=2011-10-03
#__brief__=DFS
time = 0
d = []
f = []
color = []
p = []
def DFS_VISIT( G, i ):
color[ i ] = 'gray'
global time
time += 1
d[i] = time
print i+1
for v in G[i]:
if color[v-1] == 'white':
p[v-1] = i
DFS_VISIT( G, v-1 )
color[i] = 'black'
def DFS( G ):
for i in range( len(G) ):
color.append( 'white' )
p.append( None )
d.append( 0 )
f.append( 0 )
for i in range( len(G) ):
if color[i] == 'white':
DFS_VISIT( G, i )
if __name__ == "__main__":
l1 = [ 2, 3 ]
l2 = [ 4, 5, 1 ]
l3 = [ 6, 7, 1 ]
l4 = [ 2, 8 ]
l5 = [ 2, 8 ]
l6 = [ 3, 7 ]
l7 = [ 3, 6 ]
l8 = [ 4, 5 ]
l = [ l1, l2, l3, l4, l5, l6, l7, l8 ]
DFS( l )