✅✅ Easy C++ Solution using Disjoint Set
Use Disjoint Set and apply brute force .\n\n# Code\n\n\nclass DisjointSet {\n    vector<int> rank, parent, size;\npublic:\n    DisjointSet(int n) {\n        ran
Use Disjoint Set and apply brute force .\n\n# Code\n```\n\nclass DisjointSet {\n    vector<int> rank, parent, size;\npublic:\n    DisjointSet(int n) {\n        rank.resize(n + 1, 0);\n        parent.resize(n + 1);\n        size.resize(n + 1);\n        for (int i = 0; i <= n; i++) {\n            parent[i] = i;\n            size[i] = 1;\n        }\n    }\n\n    int findUPar(int node) {\n        if (node == parent[node])\n            return node;\n        return parent[node] = findUPar(parent[node]);\n    }\n\n    void unionByRank(int u, int v) {\n        int ulp_u = findUPar(u);\n        int ulp_v = findUPar(v);\n        if (ulp_u == ulp_v) return;\n        if (rank[ulp_u] < rank[ulp_v]) {\n            parent[ulp_u] = ulp_v;\n        }\n        else if (rank[ulp_v] < rank[ulp_u]) {\n            parent[ulp_v] = ulp_u;\n        }\n        else {\n            parent[ulp_v] = ulp_u;\n            rank[ulp_u]++;\n        }\n    }\n\n    void unionBySize(int u, int v) {\n        int ulp_u = findUPar(u);\n        int ulp_v = findUPar(v);\n        if (ulp_u == ulp_v) return;\n        if (size[ulp_u] < size[ulp_v]) {\n            parent[ulp_u] = ulp_v;\n            size[ulp_v] += size[ulp_u];\n        }\n        else {\n            parent[ulp_v] = ulp_u;\n            size[ulp_u] += size[ulp_v];\n        }\n    }\n};\n\nclass Solution {\npublic:\n\n    bool is_valid(DisjointSet ds,int n,int u,int v,map<pair<int,int>,bool> &not_join){\n        ds.unionByRank(u,v);\n\n        for(auto it:not_join){\n            int u1=it.first.first;\n            int v1=it.first.second;\n            if(ds.findUPar(u1)==ds.findUPar(v1)){\n                return false;\n            }\n        }\n        return true;\n    }\n\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        \n        DisjointSet ds(n);\n        vector<bool> ans;\n        map<pair<int,int>,bool> not_join;\n\n        for(auto it:restrictions){\n            not_join[{it[0],it[1]}]=true;\n            not_join[{it[1],it[0]}]=true;\n        }\n\n        for(auto it:requests){\n\n            int u=it[0];\n            int v=it[1];\n\n            if(ds.findUPar(u)==ds.findUPar(v)){\n                ans.push_back(true);\n                continue;\n            }\n            else{\n\n                if(is_valid(ds,n,u,v,not_join)){\n                    ds.unionByRank(u,v);\n                    ans.push_back(true);\n                }\n                else{\n                    ans.push_back(false);\n                }\n\n            }\n\n        }\n\n        return ans;\n\n    }\n};\n```
['C++']