C++ || DSU || with comments || easy to understand
\nclass DSU{\nprivate:\n    vector<int> parent,rank;\n\npublic:\n    DSU(int n){\n        for(int i=0; i<n; i++){\n            parent.push_back(-1); //can show 
```\nclass DSU{\nprivate:\n    vector<int> parent,rank;\n\npublic:\n    DSU(int n){\n        for(int i=0; i<n; i++){\n            parent.push_back(-1); //can show seg fault if written like this parent[i] = -1;\n            rank.push_back(0);    // same goes for this\n        }\n    }\n\n    int find(int i){\n        if(parent[i]==-1){\n            return i;\n        }\n        return parent[i] = find(parent[i]);\n    }\n\n    void Union(int a, int b){\n        int s1 = find(a);\n        int s2 = find(b);\n\n        if(s1!=s2){\n            if(rank[s1] >= rank[s2]){\n                parent[s2] = s1;\n                rank[s1] += rank[s2];\n            }\n            else{\n                parent[s1] = s2;\n                rank[s2] += rank[s1];\n            }\n        }\n    }\n};\n\nclass Solution {\npublic:\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        DSU d(n);\n        vector<bool> ans;\n        \n        //CONCEPT:- My enemy\'s enemy is my friend\n        for(int i=0; i<requests.size(); i++){\n            DSU t = d;  //copy the previous dsu to check that the current request will be accepted or not\n            t.Union(requests[i][0],requests[i][1]);\n            bool flag = false;\n            \n            for(auto &it: restrictions){\n                if(t.find(it[0]) == t.find(it[1])){ //check that would there be any restriction which we had \n                    flag = true;                    //accepted but not supposed to be accepted\n                    break;\n                }\n            }\n            \n            if(flag==false){\n                d.Union(requests[i][0],requests[i][1]); //request approved -> true/ change in main dsu\n                ans.push_back(true);\n            }\n            else{\n                ans.push_back(false); //request rejected -> false/ no need to change main dsu\n            }\n        }\n        \n        return ans;\n        \n    }\n};\n```
['Backtracking', 'C']