Beats 94.58% Python3
Code\npython3 []\nfrom collections import defaultdict\n\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[Lis
# Code\n```python3 []\nfrom collections import defaultdict\n\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        result = []\n        network = [set([i]) for i in range(n)]\n        restrict_network = defaultdict(set)\n\n        for user1, user2 in restrictions:\n            restrict_network[user1].add(user2)\n            restrict_network[user2].add(user1)\n\n        for user1, user2 in requests:\n            if user1 == user2:\n                result.append(True)\n                continue\n\n            can_be_friends = True\n            for friend1 in network[user1]:\n                if friend1 in restrict_network:\n                    if restrict_network[friend1] & network[user2]:\n                        can_be_friends = False\n                        break\n            if not can_be_friends:\n                result.append(False)\n                continue\n\n            new_group = network[user1] | network[user2]\n            for member in new_group:\n                network[member] = new_group\n            result.append(True)\n\n        return result\n\n```
['Python3']