diff --git a/TaskB05/run.py b/TaskB05/run.py index 440c8d2..a13bcae 100644 --- a/TaskB05/run.py +++ b/TaskB05/run.py @@ -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)