import time
time1=time.time()
nodes=[(1,2,4),(0,3,5),(0,3,6),(1,2,7),
(0,5,6),(1,4,7),(2,4,7),
(3,5,6,8,9,11),(7,10,12),
(7,10,13),(8,9,14),(7,12,13),
(8,11,14),(9,11,14)]
edges,vertices,count=[],[0],0
def Check(t,eds):
if (t) in edges:
return False
Len=len(eds)
for i in range(Len-1):
e1=eds[i]
for j in range(i+1,Len):
if e1==eds[j]:
return False
return True
alledges=[[] for i in range(1908)]#This size is because I have already found the answer.
def Solve(vertice):
global count
for j in range(len(nodes[vertice])):
newvertice=nodes[vertice][j]
t1,t2=(vertice,newvertice),(newvertice,vertice)
edges.append(t1)
vertices.append(newvertice)
#print("edges=",edges,j,newvertice)
if newvertice!=14 and Check(t2,edges):
#print("vertice=",vertice)
Solve(newvertice)
elif newvertice==14:
#for i in range(len(edges)):
#alledges[count].append(edges[i])
#print("edges=",edges)
#print(vertices)
count+=1
# print("Backtrack before=",edges)
edges.pop()
vertices.pop()
#print("Backtrack after=",edges)
Solve(0)
print("count=",count)
print((time.time()-time1)*1000)
Koddaki $alledges$ adlı dizi, kenarları tutan bir dizidir, çok da gerekli de değildir sorunun çözümünde, ancak hangi kenarlardan geçtiğini görmek için gereklidir. Comment olarak görünen print satırları açılarak kod denenebilir.