✅ Swift Solution. Runtime beats 75% [2186 ms], Memory beats 100% [29.6 MB].
Approach\nAs the backbone a variation of Floyd Warshall\'s algorithm is used, which is an all-pairs shortest path algorithm, to compute the shortest distance be
# Approach\nAs the backbone a variation of `Floyd Warshall\'s` algorithm is used, which is an all-pairs shortest path algorithm, to compute the shortest distance between all pairs of nodes in the graph considering only edges with distances less than the limit. A Union-Find data structure with path compression and union by rank was used for cases with large n.\n\n## Time Complexity\nThe time complexity of this solution is `O(E * log(E) + Q * log(Q))`, where E is the number of edges and Q is the number of queries. This complexity should work efficiently for large values of n.\n\n## Space Complexity\nThe space complexity is `O(n + E + Q)`, where n is the number of nodes, E is the number of edges, and Q is the number of queries. The space is used to store the `UnionFind` data structure, the sorted edges, the sorted queries, and the result array.\n\n# Solution\n```swift\nclass Solution {\n    func distanceLimitedPathsExist(_ n: Int, _ edgeList: [[Int]], _ queries: [[Int]]) -> [Bool] {\n        var edges = edgeList.sorted { $0[2] < $1[2] }\n        var queriesWithIndex = queries.enumerated().sorted { $0.1[2] < $1.1[2] }\n        var result = Array(repeating: false, count: queries.count)\n        let uf = UnionFind(n)\n        var edgeIndex = 0\n\n        for (queryIndex, query) in queriesWithIndex {\n            let p = query[0]\n            let q = query[1]\n            let limit = query[2]\n        \n            while edgeIndex < edges.count && edges[edgeIndex][2] < limit {\n                let edge = edges[edgeIndex]\n                uf.union(edge[0], edge[1])\n                edgeIndex += 1\n            }\n        \n            result[queryIndex] = uf.find(p) == uf.find(q)\n        }\n    \n        return result\n    }\n\n    final class UnionFind {\n        var parent: [Int]\n        var rank: [Int]\n    \n        init(_ size: Int) {\n            parent = Array(0..<size)\n            rank = Array(repeating: 0, count: size)\n        }\n    \n        func find(_ x: Int) -> Int {\n            if parent[x] != x {\n                parent[x] = find(parent[x])\n            }\n            return parent[x]\n        }\n    \n        func union(_ x: Int, _ y: Int) {\n            let rootX = find(x)\n            let rootY = find(y)\n        \n            if rootX != rootY {\n                if rank[rootX] > rank[rootY] {\n                    parent[rootY] = rootX\n                } else if rank[rootX] < rank[rootY] {\n                    parent[rootX] = rootY\n                } else {\n                    parent[rootY] = rootX\n                    rank[rootX] += 1\n                }\n            }\n        }\n    }\n}\n```
['Swift']