@@ -39,7 +39,7 @@ def dfs(self, s=-2, d=-1):
3939 stack = []
4040 visited = []
4141 if s == - 2 :
42- s = list ( self .graph )[ 0 ]
42+ s = next ( iter ( self .graph ))
4343 stack .append (s )
4444 visited .append (s )
4545 ss = s
@@ -87,7 +87,7 @@ def bfs(self, s=-2):
8787 d = deque ()
8888 visited = []
8989 if s == - 2 :
90- s = list ( self .graph )[ 0 ]
90+ s = next ( iter ( self .graph ))
9191 d .append (s )
9292 visited .append (s )
9393 while d :
@@ -114,7 +114,7 @@ def topological_sort(self, s=-2):
114114 stack = []
115115 visited = []
116116 if s == - 2 :
117- s = list ( self .graph )[ 0 ]
117+ s = next ( iter ( self .graph ))
118118 stack .append (s )
119119 visited .append (s )
120120 ss = s
@@ -146,7 +146,7 @@ def topological_sort(self, s=-2):
146146 def cycle_nodes (self ):
147147 stack = []
148148 visited = []
149- s = list ( self .graph )[ 0 ]
149+ s = next ( iter ( self .graph ))
150150 stack .append (s )
151151 visited .append (s )
152152 parent = - 2
@@ -199,7 +199,7 @@ def cycle_nodes(self):
199199 def has_cycle (self ):
200200 stack = []
201201 visited = []
202- s = list ( self .graph )[ 0 ]
202+ s = next ( iter ( self .graph ))
203203 stack .append (s )
204204 visited .append (s )
205205 parent = - 2
@@ -305,7 +305,7 @@ def dfs(self, s=-2, d=-1):
305305 stack = []
306306 visited = []
307307 if s == - 2 :
308- s = list ( self .graph )[ 0 ]
308+ s = next ( iter ( self .graph ))
309309 stack .append (s )
310310 visited .append (s )
311311 ss = s
@@ -353,7 +353,7 @@ def bfs(self, s=-2):
353353 d = deque ()
354354 visited = []
355355 if s == - 2 :
356- s = list ( self .graph )[ 0 ]
356+ s = next ( iter ( self .graph ))
357357 d .append (s )
358358 visited .append (s )
359359 while d :
@@ -371,7 +371,7 @@ def degree(self, u):
371371 def cycle_nodes (self ):
372372 stack = []
373373 visited = []
374- s = list ( self .graph )[ 0 ]
374+ s = next ( iter ( self .graph ))
375375 stack .append (s )
376376 visited .append (s )
377377 parent = - 2
@@ -424,7 +424,7 @@ def cycle_nodes(self):
424424 def has_cycle (self ):
425425 stack = []
426426 visited = []
427- s = list ( self .graph )[ 0 ]
427+ s = next ( iter ( self .graph ))
428428 stack .append (s )
429429 visited .append (s )
430430 parent = - 2
0 commit comments