1 classVertice:2 def __init__(Self,index):3self.no =Index4Self.color = 0#0:white 1 Gray 2 black5SELF.VT =06 defGetnextv (self):7 returnSELF.NEXTV8 defSETNEXTV (self,*nextvertice):9SELF.NEXTV =NextverticeTen defSetColor (self,color): OneSelf.color =Color A defGetColor (self): - returnSelf.color - defincvt (self): theSELF.VT + = 1 - defGETVT (self): - returnSELF.VT - +V1 = Vertice (1) -V2 = Vertice (2) +V3 = Vertice (3) AV4 = Vertice (4) atV5 = Vertice (5) - - V1.setnextv (V2,V5) - V2.setnextv (V1,V5,V4,V3) - V3.setnextv (V2,V4) - V4.setnextv (V2,V3,V5) in V5.setnextv (V1,V2,V4) - toV100 = Vertice (100) + V100.setnextv (V1,V2,V3,V4,V5) - the defDfs_visit (v): *V.setcolor (1) $ v.incvt ()Panax Notoginseng forItinchV.GETNEXTV (): - ifIt.getcolor () = =0: the Dfs_visit (IT) +V.setcolor (2) A the dfs_visit (v100) + - forItinchV100.GETNEXTV (): $ PrintIT.GETVT () $
Python implementation of DFS algorithm