Very Simple and clean DSU Solution || JAVA
Approach\n- Simply performing the union operation to the edges until the vertex from the same component is found \n- As that same component is responsible in fo
# Approach\n- Simply performing the union operation to the edges until the vertex from the same component is found \n- As that same component is responsible in formation of the graph from the tree.\n- Perform simply union-find algorithm I have used union by size as I find it more intuitive. \n\n# Code\n```\nclass Solution {\n    public int[] findRedundantConnection(int[][] edges) {\n        int n = edges.length;\n        int[] parent = new int[n+1];\n        int[] size = new int[n+1];\n\n        for(int i=0; i<= n; i++){\n            parent[i] =i;\n            size[i] = 1;\n        }\n        int i=0;\n        for(; i< n; i++){\n            int[] edge = edges[i];\n            int u = edge[0];\n            int v = edge[1];\n\n            int ul = find(parent, u);\n            int vl = find(parent, v);\n\n            if(ul == vl) break;\n            else{\n                union(ul, vl, parent, size);\n            }\n        }\n        return edges[i];\n        \n    }\n    private int find(int[] parent, int i){\n        if(parent[i] == i){\n            return parent[i];\n        }\n        return parent[i] = find(parent, parent[i]);\n    }\n\n    private void union(int ul, int vl, int[] parent, int[] size){\n        if(ul < vl){\n            parent[ul] = vl;\n            size[ul] += size[vl];\n        }\n        else{\n            parent[vl] = ul;\n            size[vl] += size[ul]; \n        }\n    }\n}\n```
['Java']