Advertisement
Guest User

Untitled

a guest
Jul 10th, 2012
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. class Node:
  2.     def __init__(self):
  3.         self.adj = []
  4.  
  5. """
  6. abc
  7. def
  8. ghi
  9. """
  10. nodes = [Node() for _ in range(9)]
  11.  
  12. a,b,c,d,e,f,g,h,i = nodes
  13.  
  14. a.adj = [b,e,d]
  15. b.adj = [a,d,e,f,c]
  16. c.adj = [b,e,f]
  17. d.adj = [a,b,e,h,g]
  18. e.adj = [a,b,c,d,f,g,h,i]
  19. f.adj = [c,b,e,h,i]
  20. g.adj = [d,e,h]
  21. h.adj = [g,d,e,f,i]
  22. i.adj = [h,e,f]
  23.  
  24. counter = 0
  25.  
  26. def traversal(path = []):
  27.     global counter
  28.     counter += 1
  29.     for x in path[-1].adj:
  30.         if x in path:
  31.             continue
  32.         traversal(path + [x])
  33.  
  34. for x in nodes:
  35.     traversal([x])
  36. print counter
  37.  
  38. # The result is 10305
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement