[JAVA] Simple, Clear and Concise Solution with templated DSU
\nclass Solution {\n    public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        Arrays.sort(edgeList, (a, b) -> a[2] - b
```\nclass Solution {\n    public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        Arrays.sort(edgeList, (a, b) -> a[2] - b[2]);\n        Map<int[], Integer> position = new HashMap<>();\n        \n        for (int i = 0; i < queries.length; i++) {\n            position.put(queries[i], i);\n        }\n        \n        Arrays.sort(queries, (a, b) -> a[2] - b[2]);\n        \n        DSU dsu = new DSU(n);\n        boolean[] ans = new boolean[queries.length];\n        int j = 0;\n        \n        for (int[] q : queries) {\n            int limit = q[2];\n            \n            while(j < edgeList.length && edgeList[j][2] < limit) {\n                dsu.union(edgeList[j][0], edgeList[j][1]);\n                j++;\n            }\n            \n            ans[position.get(q)] = dsu.isConnected(q[0], q[1]);\n        }\n        \n        return ans;\n    }\n\t\n```\n\n<br><br><br><br>\n\t\n\tHere\'s the standard DSU template used, I have solved most of the DSU problems using the below template :)\n\t\n<br><br><br><br><br>\n\n\n```\n    \n    class DSU {\n        int[] root;\n        int[] rank;\n        \n        public DSU (int n) {\n            this.root = new int[n];\n            this.rank = new int[n];\n            \n            for (int i = 0; i < n; i++) {\n                root[i] = i;\n                rank[i] = 1;\n            }\n        }\n        \n        public int find(int x) {\n            if (root[x] == x) return x;\n            return root[x] = find(root[x]);\n        }\n        \n        public void union(int x, int y) {\n            int rootX = find(x);\n            int rootY = find(y);\n            \n            if (rootX == rootY) return;\n            \n            if (rank[rootX] > rank[rootY]) {\n                root[rootY] = rootX;\n                rank[rootX] += rank[rootY];\n                \n            } else {\n                root[rootX] = rootY;\n                rank[rootY] += rank[rootX];\n            }\n        }\n        \n        public boolean isConnected(int x, int y) {\n            return find(x) == find(y);\n        }\n    }\n}\n```
[]