Model the graph's edges as being 'active' only when their weight exceeds k, and process queries offline in descending order of k while incrementally adding edges. Use a Disjoint Set Union (DSU) to maintain connectivity components, answering each query by checking if p and q are in the same component. This yields near-linear time after sorting, which is optimal for large inputs.
Pro tip: Clarify the threshold condition early: 'strictly greater than k' vs 'at least k' changes the edge activation order and can lead to off-by-one bugs. Also mention that if queries are online, you'd need a different structure like a maximum spanning tree with binary lifting, but offline DSU is simpler and faster.
Confirm whether the condition is > k or >= k, and handle cases where p == q (always true if no edges needed) or when k is larger than all edge weights (no edges active).
Sort edges by weight descending and queries by k descending. Process queries in order, adding all edges with weight > k (or >= k) to the DSU before answering each query.
Use an efficient DSU to maintain connected components as edges are added. This ensures near-constant time per union/find operation.
For each query, check if find(p) == find(q). The overall time is O(E log E + Q log Q + (E+Q) α(N)), which is efficient for large graphs.
Mention that if queries must be answered online, you could build a maximum spanning tree and use binary lifting to answer path-minimum queries, but offline DSU is simpler and faster for batch processing.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.