[Python] Union-find, beat 100% by updating restrictions
\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        parents = [i for i in 
```\nclass Solution:\n    def friendRequests(self, n: int, restrictions: List[List[int]], requests: List[List[int]]) -> List[bool]:\n        parents = [i for i in range(n)]\n        ranks = [0] * n\n        forbidden = collections.defaultdict(set)\n        for i, j in restrictions:\n            forbidden[i].add(j)\n            forbidden[j].add(i)\n        \n        def find(i):\n            if i != parents[i]:\n                parents[i] = find(parents[i])\n            return parents[i]\n        \n        def union(p1, p2):\n            if ranks[p1] > ranks[p2]:\n                parents[p2] = p1\n            elif ranks[p1] < ranks[p2]:\n                parents[p1] = p2\n                p1, p2 = p2, p1\n            else:\n                ranks[p1] += 1\n                parents[p2] = p1\n                \n            forbidden[p1] |= forbidden[p2]\n            for i in forbidden[p2]:\n                forbidden[i].remove(p2)\n                forbidden[i].add(p1)\n            del forbidden[p2]\n        \n        ans = []\n        for i, j in requests:\n            p1 = find(i)\n            p2 = find(j)\n            if p1 == p2:\n                ans.append(True)         \n            elif p2 in forbidden[p1]:\n                ans.append(False)\n            else:\n                union(p1, p2)\n                ans.append(True)\n\n        return ans\n                    \n```
[]