simple dsu , just imagine and draw the example testcase step by step
Intuition\n Describe your first thoughts on how to solve this problem. \nRequests between two friends will be success only if both friends will lie on component
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n*Requests between two friends will be success only if both friends will lie on component other than the restricted friend requests;\nif after analysing we find request is success than we can make connection between them.*\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**we can use dsu for the above purpose mention**\n# Complexity\n- Time complexity:**O(N)**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:**O(N)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Disjoint{\npublic:\n    vector<int> parent, rank;\n    \n    Disjoint(int n) {\n        parent.resize(n+1);\n        rank.resize(n+1, 0);  \n        for(int i = 0; i <= n; i++) {\n            parent[i] = i;  \n        }\n    }\n\n    int findP(int u) {\n        if(parent[u] == u) return u;\n        return parent[u] = findP(parent[u]);  \n    }\n\n    void do_union(int u, int v) {\n        int ulp_u = findP(u);\n        int ulp_v = findP(v);\n        if(ulp_u != ulp_v) {\n            \n            if(rank[ulp_u] > rank[ulp_v]) {\n                parent[ulp_v] = ulp_u;\n            } else if(rank[ulp_u] < rank[ulp_v]) {\n                parent[ulp_u] = ulp_v;\n            } else {\n                parent[ulp_v] = ulp_u;\n                rank[ulp_u]++;\n            }\n        }\n    }\n};\n\nclass Solution {\npublic:\n    bool valid(int u, int v, Disjoint& ds, const vector<vector<int>>& restrictions) {\n        int ulp_u = ds.findP(u);\n        int ulp_v = ds.findP(v);\n        \n        for(const auto& restriction : restrictions) {\n            int r1 = ds.findP(restriction[0]);\n            int r2 = ds.findP(restriction[1]);\n            if((ulp_u == r1 && ulp_v == r2) || (ulp_u == r2 && ulp_v == r1)) {\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        Disjoint ds(n);\n        vector<bool> ans(requests.size(), false);\n        \n        for(int i = 0; i < requests.size(); i++) {\n            int u = requests[i][0];\n            int v = requests[i][1];\n            \n            if(valid(u, v, ds, restrictions)) {\n                ds.do_union(u, v);  \n                ans[i] = true;\n            }\n        }\n        \n        return ans;\n    }\n};\n\n```
['C++']