If anyone gets TLE ,make sure to do this optimization.
If someone is getting tle ,make sure to iterate using refrence in for each loop.\n\nclass union_find\n{\n\tvector<int>par;\n\tvector<int>sz;\npublic:\n\tunion_f
If someone is getting tle ,make sure to iterate using refrence in for each loop.\n```\nclass union_find\n{\n\tvector<int>par;\n\tvector<int>sz;\npublic:\n\tunion_find(int n){\n        par.resize(n);\n        sz.resize(n);\n        for(int i=0;i<n;i++){\n        \tpar[i]=i;\n        \tsz[i]=1;\n        }\n\t}\n\tint find(int x){\n\t\tif(par[x]==x)\n\t\t\treturn x;\n\t\treturn par[x]=find(par[x]);\n\t}\n\tvoid unite(int u,int v){\n\t\tint a=find(u);\n\t\tint b=find(v);\n\t\tif(not (a==b)){\n\t\t\tif(sz[a]<sz[b]){\n\t\t\t\tpar[a]=b;\n\t\t\t\tsz[b]+=sz[a];\n\t\t\t}else {\n\t\t\t\tpar[b]=a;\n\t\t\t\tsz[a]+=sz[b];\n\t\t\t}\n\t\t}\n\t}\n};\nclass Solution {\npublic:\n    vector<bool> friendRequests(int n, vector<vector<int>>& restrictions, vector<vector<int>>& requests) {\n        union_find un(n);\n        vector<bool>res;\n        for(auto &i:requests){  // & (refrence) is making the code faster, without using this i was getting tle on the same code.\n            int u=un.find(i[0]);\n            int v=un.find(i[1]);\n            bool val=true;\n            if(not (u==v)){\n                for(auto &j:restrictions){    // & (refrence) is making the code faster\n                    int x=un.find(j[0]),y=un.find(j[1]);\n                    if((u==x&&v==y)||(u==y&&v==x)){\n                        val=false;\n                        break;\n                    }\n                }\n            }\n            if(val){\n                un.unite(u,v);\n            }\n            res.push_back(val);\n        }\n        return res;\n    }\n};\n\n\n\n\n\n\n\n\n```
[]