C++ || DSU || 2 Approaches
Approach 1\n\nclass DSU {\nprivate: \n\tvector<int> parent, size, rank; \n \n\tpublic:\n    DSU(int n) {\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tparent.push_back(i
# **Approach 1**\n```\nclass DSU {\nprivate: \n\tvector<int> parent, size, rank; \n \n\tpublic:\n    DSU(int n) {\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tparent.push_back(i); \n\t\t\tsize.push_back(1); \n\t\t\trank.push_back(0); \n\t\t}\n\t}\n \n \npublic: \n\tint findPar(int node) {\n\t\tif(parent[node] == node) {\n\t\t\treturn node; \n\t\t}\n\t\treturn parent[node] = findPar(parent[node]); \n\t}\n \npublic:\n\tvoid unionSize(int u, int v) {\n\t\tint pu = findPar(u); \n\t\tint pv = findPar(v); \n\t\tif(pu == pv) {\n\t\t\treturn; \n\t\t}\n\t\tif(size[pu] < size[pv]) {\n\t\t\tparent[pu] = pv; \n\t\t\tsize[pv] += size[pu]; \n\t\t}\n\t\telse {\n\t\t\tparent[pv] = pu; \n\t\t\tsize[pu] += size[pv]; \n\t\t}\n\t}\npublic:\n\tvoid unionRank(int u, int v) {\n\t\tint pu = findPar(u); \n\t\tint pv = findPar(v); \n\t\tif(pu == pv) {\n\t\t\treturn; \n\t\t}\n\t\tif(rank[pu] < rank[pv]) {\n\t\t\tparent[pu] = pv; \n\t\t}\n\t\telse if(rank[pv] < rank[pu]){\n\t\t\tparent[pv] = pu; \n\t\t}\n\t\telse {\n\t\t\tparent[pu] = pv;\n\t\t\trank[pv]++; \n\t\t}\n\t}\n};\n\nclass Solution {\npublic:\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        DSU dsu(n);\n        vector<bool> ans;\n        \n        for(auto it: requests){\n            int x = it[0];\n            int y = it[1];\n            \n            DSU temp = dsu;\n            \n            temp.unionRank(x, y);\n            \n            bool flag = true;\n            for(auto itr: restrictions){\n                int x1 = itr[0];\n                int y1 = itr[1];\n                \n                if(temp.findPar(x1)==temp.findPar(y1)){\n                    flag=false; \n                    break;\n                }\n            }\n            \n            if(flag==true){\n                ans.push_back(true);\n                dsu.unionRank(x, y);\n            }\n            else{\n                ans.push_back(false);\n            }\n        }\n        return ans;\n    }\n};\n```\n\n# **Approach 2**\n**(with better space complexity)**\n\n```\nclass DSU {\nprivate: \n\tvector<int> parent, size, rank; \n \n\tpublic:\n    DSU(int n) {\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tparent.push_back(i); \n\t\t\tsize.push_back(1); \n\t\t\trank.push_back(0); \n\t\t}\n\t}\n \n \npublic: \n\tint findPar(int node) {\n\t\tif(parent[node] == node) {\n\t\t\treturn node; \n\t\t}\n\t\treturn parent[node] = findPar(parent[node]); \n\t}\n \npublic:\n\tvoid unionSize(int u, int v) {\n\t\tint pu = findPar(u); \n\t\tint pv = findPar(v); \n\t\tif(pu == pv) {\n\t\t\treturn; \n\t\t}\n\t\tif(size[pu] < size[pv]) {\n\t\t\tparent[pu] = pv; \n\t\t\tsize[pv] += size[pu]; \n\t\t}\n\t\telse {\n\t\t\tparent[pv] = pu; \n\t\t\tsize[pu] += size[pv]; \n\t\t}\n\t}\npublic:\n\tvoid unionRank(int u, int v) {\n\t\tint pu = findPar(u); \n\t\tint pv = findPar(v); \n\t\tif(pu == pv) {\n\t\t\treturn; \n\t\t}\n\t\tif(rank[pu] < rank[pv]) {\n\t\t\tparent[pu] = pv; \n\t\t}\n\t\telse if(rank[pv] < rank[pu]){\n\t\t\tparent[pv] = pu; \n\t\t}\n\t\telse {\n\t\t\tparent[pu] = pv;\n\t\t\trank[pv]++; \n\t\t}\n\t}\n};\n\nclass Solution {\npublic:\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        DSU dsu(n);\n        vector<bool> ans;\n        \n        for(auto &it: requests){\n            int x = it[0];\n            int y = it[1];\n            int px = dsu.findPar(x);\n            int py = dsu.findPar(y);\n            \n            bool flag=true;\n            if(px!=py){\n                for(auto &itr: restrictions){\n                    int pu = dsu.findPar(itr[0]);\n                    int pv = dsu.findPar(itr[1]);\n                    \n                    if((pu==px && pv==py) || pu==py && pv==px){\n                        flag=false;\n                        break;\n                    }\n                }\n            }\n            if(flag==false){\n                ans.push_back(false);\n            }\n            else{\n                ans.push_back(true);\n                dsu.unionRank(x, y);\n            }\n        }\n        return ans;\n    }\n};\n```
[]