DSU c++
\nclass Solution {\npublic:\n    static bool cmp(vector<int> &a,vector<int> &b)\n    {\n        return a[2]<b[2];\n    }\n    \n    vector<int> parent;\n    \n 
```\nclass Solution {\npublic:\n    static bool cmp(vector<int> &a,vector<int> &b)\n    {\n        return a[2]<b[2];\n    }\n    \n    vector<int> parent;\n    \n    int find(int x)\n    {\n        if(parent[x]==x)return x;\n        return parent[x] = find(parent[x]);\n    }\n    \n    void Union(int x,int y)\n    {\n        int lx = find(x);\n        int ly = find(y);\n        parent[lx] = ly;\n    }\n    \n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edges, vector<vector<int>>& q) {\n        int m = q.size();\n        for(int i = 0;i<m;i++)\n        {\n            q[i].push_back(i);\n        }\n        \n        parent.resize(n,0);\n        for(int i = 0;i<n;i++)\n            parent[i] = i;\n        sort(edges.begin(),edges.end(),cmp);\n        sort(q.begin(),q.end(),cmp);\n        \n        int i = 0;\n        vector<bool> ans(m,0);\n        \n        for(auto it:q)\n        {\n            while(i<edges.size() and edges[i][2]<it[2])\n            {\n                Union(edges[i][0],edges[i][1]);\n                i++;\n            }\n            ans[it[3]] = (find(it[0])==find(it[1]));\n        }\n        return ans;        \n    }\n};\n```
['C']