✅ [Python] UnionFind || Easy to Understand with Explanation
\nclass UnionFindSet(object):\n    def __init__(self, n):\n        self.data = range(n)\n\n    def find(self, x):\n        while x <> self.data[x]:\n           
```\nclass UnionFindSet(object):\n    def __init__(self, n):\n        self.data = range(n)\n\n    def find(self, x):\n        while x <> self.data[x]:\n            x = self.data[x]\n        return x\n\n    def union(self, x, y):\n        self.data[self.find(x)] = self.find(y)\n\n    def speedup(self):\n        for i in range(len(self.data)):\n            self.data[i] = self.find(i)\n\n\nclass Solution(object):\n    def friendRequests(self, n, restrictions, requests):\n        uf = UnionFindSet(n)\n        ret = [True] * len(requests)\n        for k, [x, y] in enumerate(requests):  # Process Requests Sequentially\n            xh = uf.find(x)  # backup the head of x for undo\n            uf.union(x, y)  # link [x, y] and verify if any restriction triggers\n            for [i, j] in restrictions:\n                if uf.find(i) == uf.find(j):\n                    ret[k] = False\n                    break\n            if not ret[k]:  # if any restriction triggers, undo\n                uf.data[xh] = xh\n            else:\n                uf.speedup()\n        return ret\n```\n**If you have any questoins, feel free to ask. If you like the solution and explanation, please upvote!**
['Union Find', 'Python']