Implement a function called can_rabbits_play that determines the interactions of rabbits across a series of operations. Each operation can either unite two rabbits, remove the unity between two rabbits, or check if two rabbits are connected in a playgroup.
Functionality Requirements
Input Parameters:
n (int): The total number of rabbits, indexed from 0 to n-1.
k (int): The total number of operations to be processed.
operations (list of tuples): A list containing k operations, where each operation is defined as:
A tuple (t, a, b):
t (int): The type of operation:
1: Unite rabbits a and b.
2: Remove any connection between rabbits a and b.
3: Check if rabbits a and b are in the same playgroup.
a (int): The index of the first rabbit.
b (int): The index of the second rabbit.
Output:
Return a list of strings containing "YES" or "NO" for each check operation (type 3). Each string indicates whether the two rabbits are part of the same playgroup.
Input/Output Example
python
# Example Input
n = 5
k = 5
operations = [
(1, 0, 1),
(1, 1, 2),
(3, 0, 2),
(2, 1, 2),
(3, 0, 2),
]
# Example Output
['YES', 'NO']
Additional Notes
The function should efficiently handle up to n and k values up to 10^5.
Implement the solution in a file called /app/solution.py.