JAVA || Union Find || Disjoint Set
\nclass Solution {\n    \n    int[] parent;\n    int[] rank;\n    \n    Solution(){\n        int n = 100004;\n        parent = new int[n];\n        rank = new i
```\nclass Solution {\n    \n    int[] parent;\n    int[] rank;\n    \n    Solution(){\n        int n = 100004;\n        parent = new int[n];\n        rank = new int[n];\n        for(int i = 0;i<n;i++)\n            parent[i] = i;\n    }\n    \n    public void union(int u, int v){\n        int pu = findParent(u), pv = findParent(v);\n        int ru = rank[pu] , rv = rank[pv];\n        \n        if(pu == pv)\n            return;\n        if(ru < rv){\n            parent[pu] = pv;\n        }else if(rv < ru)\n            parent[pv] = pu;\n        else{\n            parent[pu] = pv;\n            rank[pv]++;\n        }\n        return;\n    }\n    \n    public int findParent(int u){\n        if( u != parent[u])\n            parent[u] = findParent(parent[u]);\n        return parent[u] ;\n    }\n    \n    public boolean connected(int u, int v){\n        return findParent(u) == findParent(v);\n    }\n    \n    public void sort(int[][] query){\n         Arrays.sort(query, new Comparator<int[] >(){\n            @Override\n            public int compare(int[] first, int[] second){\n                return first[2] - second[2]; \n            }\n        });\n    }\n    \n    public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        int no_of_query = queries.length;\n        int[][] query = new int[no_of_query][4];\n        int i = 0, j = 0;\n        for( i =0 ;i < no_of_query ; i++){\n            query[i][0] = queries[i][0];\n            query[i][1] = queries[i][1];\n            query[i][2] = queries[i][2];\n            query[i][3] = i;\n        }\n\n        sort(query);\n        sort(edgeList);\n       \n        int currentEdge = 0;\n        int edges = edgeList.length;\n        boolean[] ans = new boolean[no_of_query];\n        for(i = 0;i < no_of_query ; i++){\n            int u = query[i][0], v = query[i][1], limit = query[i][2], ind = query[i][3];\n            while( currentEdge < edges && edgeList[currentEdge][2] < limit){\n                int p = edgeList[currentEdge][0], q = edgeList[currentEdge][1] ;\n                union(p,q);\n                currentEdge++;\n            }\n            ans[ind] = findParent(u) == findParent(v);\n        }\n        return ans;\n    }\n}\n```
['Union Find', 'Graph', 'Sorting', 'Java']