Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class graph:
- def __init__(self,graph):
- self.graph = graph
- self.greedy = len(graph) #greedy people
- self.seats = len(graph[0]) #total seats map
- def search(self, greed, match, flag):
- for i in range(self.seats):
- if self.graph[greed][i] and flag[i] == False:
- flag[i] = True
- if match[i] == -1 or self.search(match[i], match, flag):
- match[i] = greed
- return True
- return False
- def total(self):
- match = [-1] * self.seats
- result = 0
- for i in range(self.greedy):
- flag = [False] * self.seats
- if self.search(i, match, flag):
- result += 1
- return result
- egraph =[[1, 1, 1, 0, 0, 0],
- [1, 0, 0, 1, 0, 0],
- [0, 0, 1, 0, 0, 0],
- [0, 0, 1, 1, 0, 0],
- [0, 1, 0, 0, 0, 0],
- [0, 0, 1, 0, 1, 1]]
- var=graph(egraph)
- print(var.total())
Add Comment
Please, Sign In to add comment