Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self):
- self.adj = []
- """
- abc
- def
- ghi
- """
- nodes = [Node() for _ in range(9)]
- a,b,c,d,e,f,g,h,i = nodes
- a.adj = [b,e,d]
- b.adj = [a,d,e,f,c]
- c.adj = [b,e,f]
- d.adj = [a,b,e,h,g]
- e.adj = [a,b,c,d,f,g,h,i]
- f.adj = [c,b,e,h,i]
- g.adj = [d,e,h]
- h.adj = [g,d,e,f,i]
- i.adj = [h,e,f]
- counter = 0
- def traversal(path = []):
- global counter
- counter += 1
- for x in path[-1].adj:
- if x in path:
- continue
- traversal(path + [x])
- for x in nodes:
- traversal([x])
- print counter
- # The result is 10305
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement