Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import itertools
  2.  
  3. def dfs(vertices, i):
  4. global seen
  5. global has_path
  6.  
  7. if has_path == True:
  8. return
  9. if i==7:
  10. has_path = True
  11. return
  12. if seen[i]==1:
  13. return
  14.  
  15. seen[i] = 1
  16.  
  17. for n in vertices[i]:
  18. dfs(vertices,n)
  19.  
  20. seen[i]=0
  21.  
  22.  
  23. cnt = 0
  24. total_cnt = 0
  25. for seq in itertools.product("10", repeat=13):
  26.  
  27. vertices = [[] for i in range(8)]
  28.  
  29.  
  30. if(seq[0]=='1'):
  31. vertices[0].append(1)
  32. if(seq[1]=='1'):
  33. vertices[0].append(2)
  34. if(seq[2]=='1'):
  35. vertices[0].append(3)
  36. if(seq[3]=='1'):
  37. vertices[1].append(2)
  38. vertices[2].append(1)
  39. if(seq[4]=='1'):
  40. vertices[1].append(4)
  41. if(seq[5]=='1'):
  42. vertices[2].append(3)
  43. vertices[3].append(2)
  44. if(seq[6]=='1'):
  45. vertices[2].append(5)
  46. if(seq[7]=='1'):
  47. vertices[3].append(6)
  48. if(seq[8]=='1'):
  49. vertices[4].append(5)
  50. vertices[5].append(4)
  51. if(seq[9]=='1'):
  52. vertices[4].append(7)
  53. if(seq[10]=='1'):
  54. vertices[5].append(6)
  55. vertices[6].append(5)
  56. if(seq[11]=='1'):
  57. vertices[5].append(7)
  58. if(seq[12]=='1'):
  59. vertices[6].append(7)
  60.  
  61.  
  62. seen = [0,0,0,0,0,0,0]
  63. has_path = False
  64.  
  65. dfs(vertices, 0)
  66. if has_path is True:
  67. cnt+=1
  68. total_cnt +=1
  69.  
  70. print(cnt)
  71. print(total_cnt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement