C++ DSU solution
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 UnionFind {\npublic:\n    UnionFind(int n) : parent(n), rank(n, 0) {\n        for (int i = 0; i < n; ++i) {\n            parent[i] = i;\n        }\n    }\n    \n    int find(int u) {\n        if (parent[u] != u) {\n            parent[u] = find(parent[u]);\n        }\n        return parent[u];\n    }\n    \n    void unite(int u, int v) {\n        int pu = find(u);\n        int pv = find(v);\n        if (pu != pv) {\n            if (rank[pu] > rank[pv]) {\n                parent[pv] = pu;\n            } else if (rank[pu] < rank[pv]) {\n                parent[pu] = pv;\n            } else {\n                parent[pv] = pu;\n                rank[pu]++;\n            }\n        }\n    }\n\nprivate:\n    vector<int> parent;\n    vector<int> rank;\n};\n\n\nclass Solution {\npublic:\n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edgeList, vector<vector<int>>& queries) {\n        sort(edgeList.begin(), edgeList.end(), [](const vector<int>& a, const vector<int>& b) {\n        return a[2] < b[2];\n    });\n\n    // Add an index to each query to keep track of the original order\n    for (int i = 0; i < queries.size(); ++i) {\n        queries[i].push_back(i);\n    }\n\n    // Sort the queries by their limit\n    sort(queries.begin(), queries.end(), [](const vector<int>& a, const vector<int>& b) {\n        return a[2] < b[2];\n    });\n\n    // Initialize the Union-Find structure\n    UnionFind uf(n);\n\n    vector<bool> answer(queries.size());\n    int edgeIndex = 0;\n\n    // Process each query\n    for (const auto& query : queries) {\n        int p = query[0];\n        int q = query[1];\n        int limit = query[2];\n        int queryIndex = query[3];\n\n        // Add all edges with distance less than the current query limit to the Union-Find structure\n        while (edgeIndex < edgeList.size() && edgeList[edgeIndex][2] < limit) {\n            uf.unite(edgeList[edgeIndex][0], edgeList[edgeIndex][1]);\n            edgeIndex++;\n        }\n\n        // Check if p and q are in the same connected component\n        if (uf.find(p) == uf.find(q)) {\n            answer[queryIndex] = true;\n        } else {\n            answer[queryIndex] = false;\n        }\n    }\n\n    return answer;\n\n    }\n};\n```
['C++']