Question: There are n students (numbered 0 through n 1) in class, and they need to be partitioned into teams. The teams do not need to
There are n students (numbered 0 through n 1) in class, and they need to be partitioned into teams. The teams do not need to have the same sizesome can have size 1, some can have size 2, and so on with no limit on team size. There are several requests from pairs of studentssome want to be on the same team, and others want not to be on the same team. Write a Python function everyone_happy(n, request_same, request_different) that determines whether its possible to satisfy all requests (returning True if possible and False if not). Here, request_same is the list of all pairs of students requesting to be on the same team, and request_different is the list of all pairs of students requesting to be on different teams. The running time should be O(n + mlog n) where m is the total number of requests. (Hint: Recall our implementation of Union-Find in Kruskals algorithm.) For example, everyone_happy(4, [(0, 1), (3, 1), (2, 3)], [(0, 2)]) should return False .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
