Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\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    int find(int node, vector<int>& parent)\n    {\n        if(node == parent[node])\n            return node;\n        return parent[node] = find(parent[node], parent);\n    }\n    void Union(int node0, int node1, vector<int>& parent)\n    {\n        int par0 = find(node0, parent); \n        int par1 = find(node1, parent);\n        if(par0 == par1)\n            return;\n        parent[par0] = par1;\n    }\n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edges, vector<vector<int>>& queries) {\n        int q = queries.size();\n        int sz = edges.size(); \n        vector<int> parent(n, 0); \n        for(int i = 0; i < n; i++) parent[i] = i;\n        sort(edges.begin(), edges.end(), [&](vector<int>& edge1, vector<int>& edge2){\n            return edge1[2] < edge2[2];\n        });\n        for(int i = 0; i < q; i++) queries[i].push_back(i);\n        sort(queries.begin(), queries.end(), [&](vector<int>& query1,vector<int>& query2) \n        {\n            return query1[2] < query2[2];\n        });\n        vector<bool> ans(q, false);\n        int edgeMoment = 0; \n        for(int eachQuery = 0; eachQuery < q; eachQuery++) \n        {\n            int currQueryWeight = queries[eachQuery][2]; \n            while(edgeMoment < sz && edges[edgeMoment][2] < currQueryWeight)\n            Union(edges[edgeMoment][0], edges[edgeMoment][1], parent), edgeMoment++;\n            if(find(queries[eachQuery][0], parent) == \n            find(queries[eachQuery][1], parent))  {\n\n                ans[queries[eachQuery][3]] = true;\n            }\n        }\n        return ans;\n    }\n};\n```
['C++']