DSU solution || C++
Intuition\n Describe your first thoughts on how to solve this problem. \nIn queries we have to find if there is a path from u to v such that maximum edgewt is l
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn queries we have to find if there is a path from u to v such that maximum edgewt is less that limit.This can be done through dsu . \nBut again we can\'t make graph for each queries , so we will reuse the graph made earlier through dsu. for this we will sort the queries on the basis of limit. \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    \nclass DisjointSet\n{\npublic:\n    vector<int> size, parent;\n    DisjointSet(int n)\n    {\n        size.resize(n + 1, 1);\n        parent.resize(n + 1);\n        for (int i = 0; i <= n; i++)\n        {\n            parent[i] = i;\n        }\n    }\n    int findUPar(int node)\n    {\n        if (node == parent[node])\n            return node;\n        return parent[node] = findUPar(parent[node]);\n    }\n    void unionBySize(int u, int v)\n    {\n        int ulp_u = findUPar(u), ulp_v = findUPar(v);\n        if (ulp_u == ulp_v)\n            return;\n        if (size[ulp_u] >= size[ulp_v])\n        {\n            parent[ulp_v] = ulp_u;\n            size[ulp_u] += size[ulp_v];\n        }\n        else if (size[ulp_u] < size[ulp_v])\n        {\n            parent[ulp_u] = ulp_v;\n            size[ulp_v] += size[ulp_u];\n        }\n    }\n};\n\n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edgeList, vector<vector<int>>& queries) {\n        vector<vector<int>> edges;\n        DisjointSet ds(n);\n        for(auto it:edgeList)\n        {\n            int u=it[0],v=it[1],wt=it[2];\n            edges.push_back({wt,u,v});\n        }\n        sort(edges.begin(),edges.end());\n        vector<vector<int>> q;\n        int i=0;\n        for(auto it:queries)\n        {\n            int u=it[0],v=it[1],wt=it[2];\n            q.push_back({wt,u,v,i++});\n        }\n      \n       \n        sort(q.begin(),q.end());\n         i=0;\n        vector<bool> ans(q.size());\n        for(auto it:q)\n        {\n            int wt=it[0],u=it[1],v=it[2],ind =it[3];\n           // cout<<wt<<" \\n";\n            while(i<edges.size())\n            {\n                int dst=edges[i][0],x=edges[i][1],y=edges[i][2];\n                if(dst>=wt)\n                break;\n               // cout<<wt<<" "<<dst<<endl;\n                ds.unionBySize(x,y);\n                i++;\n            }\n            if(ds.findUPar(u)==ds.findUPar(v))\n            ans[ind]=1;\n            else\n            ans[ind]=0;\n\n        }\n           return ans;\n\n\n\n\n    }\n};\n```
['C++']