Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools
- def dfs(vertices, i):
- global seen
- global has_path
- if has_path == True:
- return
- if i==7:
- has_path = True
- return
- if seen[i]==1:
- return
- seen[i] = 1
- for n in vertices[i]:
- dfs(vertices,n)
- seen[i]=0
- cnt = 0
- total_cnt = 0
- for seq in itertools.product("10", repeat=13):
- vertices = [[] for i in range(8)]
- if(seq[0]=='1'):
- vertices[0].append(1)
- if(seq[1]=='1'):
- vertices[0].append(2)
- if(seq[2]=='1'):
- vertices[0].append(3)
- if(seq[3]=='1'):
- vertices[1].append(2)
- vertices[2].append(1)
- if(seq[4]=='1'):
- vertices[1].append(4)
- if(seq[5]=='1'):
- vertices[2].append(3)
- vertices[3].append(2)
- if(seq[6]=='1'):
- vertices[2].append(5)
- if(seq[7]=='1'):
- vertices[3].append(6)
- if(seq[8]=='1'):
- vertices[4].append(5)
- vertices[5].append(4)
- if(seq[9]=='1'):
- vertices[4].append(7)
- if(seq[10]=='1'):
- vertices[5].append(6)
- vertices[6].append(5)
- if(seq[11]=='1'):
- vertices[5].append(7)
- if(seq[12]=='1'):
- vertices[6].append(7)
- seen = [0,0,0,0,0,0,0]
- has_path = False
- dfs(vertices, 0)
- if has_path is True:
- cnt+=1
- total_cnt +=1
- print(cnt)
- print(total_cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement