[Python] Union-Friends
Explanation\nUse union-found to union friends.\nFor each request, check if doesn\'t obey any restrictions.\n\n\n# Complexity\nUnion-find operation with rank and
# **Explanation**\nUse union-found to union friends.\nFor each request, check if doesn\'t obey any restrictions.\n<br>\n\n# **Complexity**\nUnion-find operation with rank and path comression,has amotized `O(1)`\nTime `O(requests * restrictions)`\nSpace `O(n)`\n<br>\n\n**Python**\n```py\n    def friendRequests(self, n, restrictions, requests):\n        uf = {i: i for i in xrange(n)}\n        res = []\n\n        def find(i):\n            if i != uf[i]:\n                uf[i] = find(uf[i])\n            return uf[i]\n\n        for i, j in requests:\n            success = True\n            pi, pj = find(i), find(j)\n            if pi != pj:\n                for x, y in restrictions:\n                    px, py = find(x), find(y)\n                    if (px, py) == (pi, pj) or (px, py) == (pj, pi):\n                        success = False\n                        break\n            if success:\n                uf[pj] = pi\n            res.append(success)\n        return res\n```\n
[]