MediumRating 1659
3532. Path Existence Queries in a Graph I
arrayhash-tablebinary-searchunion-findgraph
解題說明
C++ 解法
複雜度分析
虛擬碼
1. Create index array [0, 1, ..., n-1], sort by nums[idx] 2. Scan sorted indices: assign component IDs - Start with compId = 0 - For each consecutive pair in sorted order: if nums difference > maxDiff, increment compId - comp[idx[i]] = compId 3. For each query [u, v]: answer true if comp[u] == comp[v] 4. Return results