DSU UNION by SIZE || JAVA
\nclass Solution {\n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        Dsu dsu = new Dsu(n);\n        \n        boole
```\nclass Solution {\n    public boolean[] friendRequests(int n, int[][] restrictions, int[][] requests) {\n        Dsu dsu = new Dsu(n);\n        \n        boolean[] ans = new boolean[requests.length];\n        int i=0;\n        \n        for(int[]x : requests){\n            int pu = dsu.findpar(x[0]);\n            int pv= dsu.findpar(x[1]);\n            boolean fl = true;\n            if(pu!=pv){\n                for(int[] x2:restrictions){\n                    int pu1 = dsu.findpar(x2[0]);\n                    int pv1 = dsu.findpar(x2[1]);\n                    \n                    if((pu == pu1 && pv == pv1) || (pu == pv1 && pv ==pu1)){\n                        fl = false;\n                        break;\n                    }\n                }\n                if(fl){\n                    dsu.union(pu,pv);\n                }\n               \n            }\n            ans[i++] = fl;\n        }\n        return ans;\n    }\n}\nclass Dsu{\n    int[] parent = new int[1000];\n    int[]size = new int[1000];\n    \n    Dsu(int n){\n        \n        for(int i=0;i<n;i++){\n            parent[i] = i;\n            size[i] = 0;\n        }\n    }\n    \n    public int findpar(int n){\n        if(parent[n] == n)return n;\n        return parent[n] = findpar(parent[n]);\n    }\n    \n    public void union(int u ,int v){\n        int pu = findpar(u);\n        int pv = findpar(v);\n        \n        if(pu==pv)return;\n        \n        if(size[pu]<size[pv]){\n            parent[pu]=pv;\n            size[pv] += size[pu];\n        }else{\n            parent[pv] = pu;\n            size[pu] += size[pv];\n        }\n    }\n}\n```
['Java']