Imagine you're designing a smart navigation system for a delivery network where roads have different weight limits. You need to quickly answer queries about whether packages can be delivered between two locations using only roads that can handle weights strictly less than a given limit.
You're given an undirected graph with n nodes representing locations, defined by edgeList where edgeList[i] = [ui, vi, disi] represents a road between locations ui and vi with weight capacity disi. Note that there may be multiple roads between two locations, and some locations might be unreachable from others.
Your task: Implement the DistanceLimitedPathsExist class that can efficiently answer multiple queries about path existence under weight constraints.
The class should support:
DistanceLimitedPathsExist(int n, int[][] edgeList)- Initialize with the graphboolean query(int p, int q, int limit)- Returntrueif there's a path fromptoqusing only edges with weight strictly less thanlimit
Input & Output
Visualization
Time & Space Complexity
Sorting edges and queries, plus Union-Find operations with inverse Ackermann function
Union-Find structure, sorted arrays, and result storage
Constraints
- 2 โค n โค 104
- 0 โค edgeList.length โค min(n*(n-1)/2, 104)
- edgeList[i].length == 3
- 0 โค ui, vi, p, q โค n-1
- ui != vi
- 0 โค disi, limit โค 109
- At most 104 calls will be made to query