Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. class graph:
  2. def __init__(self,graph):
  3. self.graph = graph
  4. self.greedy = len(graph) #greedy people
  5. self.seats = len(graph[0]) #total seats map
  6.  
  7. def search(self, greed, match, flag):
  8. for i in range(self.seats):
  9. if self.graph[greed][i] and flag[i] == False:
  10. flag[i] = True
  11. if match[i] == -1 or self.search(match[i], match, flag):
  12. match[i] = greed
  13. return True
  14. return False
  15.  
  16.  
  17. def total(self):
  18. match = [-1] * self.seats
  19. result = 0
  20. for i in range(self.greedy):
  21. flag = [False] * self.seats
  22. if self.search(i, match, flag):
  23. result += 1
  24. return result
  25.  
  26.  
  27.  
  28.  
  29. egraph =[[1, 1, 1, 0, 0, 0],
  30. [1, 0, 0, 1, 0, 0],
  31. [0, 0, 1, 0, 0, 0],
  32. [0, 0, 1, 1, 0, 0],
  33. [0, 1, 0, 0, 0, 0],
  34. [0, 0, 1, 0, 1, 1]]
  35.  
  36. var=graph(egraph)
  37.  
  38. print(var.total())
Add Comment
Please, Sign In to add comment