Python Union Find & Bitmask,O(M+N)
uni.rep means friends in one group, uni.cnf means this group cannot make friends with these people.\n\nclass UniSet:\n    def __init__(self, n):\n        self.u
*uni.rep* means friends in one group, *uni.cnf* means this group cannot make friends with these people.\n```\nclass UniSet:\n    def __init__(self, n):\n        self.uni = list(range(n))\n        self.rep = [1 << i for i in range(n)]\n        self.cnf = [0] * n\n    \n    def find(self, x):\n        if self.uni[x] != x: self.uni[x] = self.find(self.uni[x])\n        return self.uni[x]\n    \n    def same(self, x, y):\n        return self.find(x) == self.find(y)\n\n    def check_merge(self, x, y):\n        x, y = self.find(x), self.find(y)\n        if self.cnf[x] & self.rep[y] | self.rep[x] & self.cnf[y]: return False\n        x, y = min(x, y), max(x, y)\n        self.uni[y] = x\n        self.rep[x] |= self.rep[y]\n        self.cnf[x] |= self.cnf[y]\n        return True\n\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        uni = UniSet(n)\n        for x, y in restrictions:\n            uni.cnf[x] |= 1 << y\n            uni.cnf[y] |= 1 << x\n        return [uni.check_merge(x, y) for x, y in requests]\n```
[]