2076. Process Restricted Friend Requests.cpp
Code\n\nclass UnionFind {\npublic: \n    vector<int> parent, rank; \n    UnionFind(int n) {\n        parent.resize(n); \n        iota(begin(parent), end(parent)
**Code**\n```\nclass UnionFind {\npublic: \n    vector<int> parent, rank; \n    UnionFind(int n) {\n        parent.resize(n); \n        iota(begin(parent), end(parent), 0); \n        rank.resize(n); \n        fill(rank.begin(), rank.end(), 1); \n    } \n    \n    int find(int p) {\n        if (parent[p] != p) \n            parent[p] = find(parent[p]); \n        return parent[p]; \n    }\n    \n    bool connect(int p, int q) {\n        /* union with rank */\n        int prt = find(p), qrt = find(q); \n        if (prt == qrt) return false; \n        if (rank[prt] > rank[qrt]) swap(prt, qrt);\n        parent[prt] = qrt; \n        rank[qrt] += rank[prt]; \n        return true; \n    }\n};\nclass Solution {\npublic:\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        vector<bool> ans; \n        UnionFind *uf = new UnionFind(n); \n        for (auto& request : requests) {\n            int u = uf->find(request[0]), v = uf->find(request[1]); \n            bool found = false; \n            for (auto& restriction : restrictions) {\n                int x = uf->find(restriction[0]), y = uf->find(restriction[1]); \n                if ((u == x && v == y) || (u == y && v == x)) {\n                    found = true; \n                    break; \n                }\n            }\n            ans.push_back(!found); \n            if (!found) uf->connect(u, v); \n        }\n        delete uf; \n        return ans; \n    }\n};\n```
['C']