A ball is participated by n students from Kumpula and n students from Viikki. The students of each campus are numbered 1,2,\dots,n.
Each dancing pair has one student from Kumpula and one from Viikki, and you know all pairs that are willing to dance with each other. Each student can belong to at most one dancing pair. What is the maximum number of pairs that can be formed?
You may assume that n is at most 50 and that the methods of the class are called at most 100 times.
In a file ball.py
, implement a class Ball
with the following methods:
- constructor with n as a parameter
add_pair
declares that a student a from Kumpula and a student b from Viikki are willing to dance with each othercalculate
returns the maximum number of dancing pairs
class Ball: def __init__(self,n): # TODO def add_pair(self,a,b): # TODO def calculate(self): # TODO if __name__ == "__main__": b = Ball(4) print(b.calculate()) # 0 b.add_pair(1,2) print(b.calculate()) # 1 b.add_pair(1,3) b.add_pair(3,2) print(b.calculate()) # 2