Return immediately if edge starts and finishes in the same node
This commit is contained in:
parent
2efbb9182d
commit
6ae119a40b
@ -26,6 +26,9 @@ def dfs(graph, start):
|
||||
while stack:
|
||||
edge = stack.pop()
|
||||
#print('Current edge: {edge}'.format(edge = edge))
|
||||
#return immediately if cycle is detected
|
||||
if edge[0] == edge[2]:
|
||||
return [-1]
|
||||
if edge not in visited:
|
||||
visited.add(edge)
|
||||
children = set()
|
||||
@ -37,7 +40,7 @@ def dfs(graph, start):
|
||||
return [-1]
|
||||
return visited
|
||||
|
||||
|
||||
# load atand format from stdin
|
||||
for line in sys.stdin:
|
||||
line = line.replace('\n', '')
|
||||
move = atandt_desc_pattern.match(line)
|
||||
|
Loading…
Reference in New Issue
Block a user