return result instead of using references
This commit is contained in:
parent
5525015ff1
commit
538b07f0da
1 changed files with 6 additions and 7 deletions
13
cycles.py
13
cycles.py
|
@ -72,9 +72,8 @@ point_stack = list()
|
||||||
marked = dict()
|
marked = dict()
|
||||||
marked_stack = list()
|
marked_stack = list()
|
||||||
|
|
||||||
def backtrack(v, f):
|
def backtrack(v):
|
||||||
g = [False]
|
f = False
|
||||||
f[0] = False
|
|
||||||
point_stack.append(v)
|
point_stack.append(v)
|
||||||
marked[v] = True
|
marked[v] = True
|
||||||
marked_stack.append(v)
|
marked_stack.append(v)
|
||||||
|
@ -83,10 +82,9 @@ def backtrack(v, f):
|
||||||
A[w] = 0
|
A[w] = 0
|
||||||
elif w==s:
|
elif w==s:
|
||||||
print_point_stack()
|
print_point_stack()
|
||||||
f[0] = True
|
f = True
|
||||||
elif not marked[w]:
|
elif not marked[w]:
|
||||||
backtrack(w, g)
|
f = backtrack(w) or f
|
||||||
f[0] = f[0] or g[0]
|
|
||||||
if f:
|
if f:
|
||||||
while marked_stack[-1] != v:
|
while marked_stack[-1] != v:
|
||||||
u = marked_stack.pop()
|
u = marked_stack.pop()
|
||||||
|
@ -94,12 +92,13 @@ def backtrack(v, f):
|
||||||
marked_stack.pop()
|
marked_stack.pop()
|
||||||
marked[v] = False
|
marked[v] = False
|
||||||
point_stack.pop()
|
point_stack.pop()
|
||||||
|
return f
|
||||||
|
|
||||||
for i in range(len(A)):
|
for i in range(len(A)):
|
||||||
marked[i] = False
|
marked[i] = False
|
||||||
|
|
||||||
for s in range(len(A)):
|
for s in range(len(A)):
|
||||||
backtrack(s, [False])
|
backtrack(s)
|
||||||
while marked_stack:
|
while marked_stack:
|
||||||
u = marked_stack.pop()
|
u = marked_stack.pop()
|
||||||
marked[u] = False
|
marked[u] = False
|
||||||
|
|
Loading…
Reference in a new issue