[python3] faster than 100%, extensively explained. (assign group for each people)
\n\n# Code\npython3 []\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        
\n\n# Code\n```python3 []\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        # start by assigning people to group (group_idx[person]=group)\n        # group index is defined as minimum index of person in group\n        # initially, group_idx[i] = i for all i in range(n), since everyone is in their own group\n\n        # we also keep ban_set[i] = set()\n            # set of group indices that cannot be merged with group i \n        \n        # upon each request, we think about "merging" two groups A and B, which two people a,b are in\n            # they will all become indirect friends if two groups merge\n        \n        # case 1 : A == B\n            # two people are already in same group. append True to answer\n        # case 2 : A and B are in each other\'s ban_set\n            # cannot merge. append False to answer\n        # case 3 : B is not in ban_set[A] and vice versa:\n            # merge ok. merge and update by\n                # (1) update all group_idx. determine new group idx by min(A,B) and update all group_idx\n                # (2) update ban_set. ban_set[min(A,B)] should newly include all of ban_set[max(A,B)]\n        \n        def update_group(x,y):\n            """\n            set group_idx of everyone that was in group y to group x\n            """\n            # TODO: can we do it efficiently?\n            for a in group_idx:\n                if group_idx[a] == y:\n                    group_idx[a] = x\n\n        \n        def update_ban(x,y):\n            """\n            group x and group y is being merged to group x\n            add all that was in ban_set[y] to ban_set[x]\n            also, other groups which were banning group y should now also ban group x (because x and y is merged to x)\n            """\n            ban_set[x] |= ban_set[y]\n            for a in ban_set:\n                if y in ban_set[a]:\n                    ban_set[a].add(x)\n\n        group_idx = {i:i for i in range(n)}\n        ban_set = defaultdict(set)\n        # TODO: merging operation is commutative. Do we really have to keep track of both ban_set[A] and ban_set[B]?\n        for x,y in restrictions:\n            ban_set[x].add(y)\n            ban_set[y].add(x)\n        \n        ans = []\n        for a,b in requests:\n            A = group_idx[a]\n            B = group_idx[b]\n            if A == B:\n                ans.append(True)\n            elif (A in ban_set[B]) or (B in ban_set[A]):\n                ans.append(False)\n            else:\n                ans.append(True)\n                update_group(min(A,B), max(A,B))\n                update_ban(min(A,B), max(A,B))\n        \n        return ans\n\n\n\n\n```
['Python3']