Technique · CP 2400+
Kruskal Reconstruction Tree
During Kruskal, every successful union creates a new node whose value is the edge weight and whose children are the two roots. The bottleneck weight between u and v is then their LCA's value, and 'vertices reachable from v using edges <= x' is a single subtree.
0/4 solved
Recognise it
The signal
minimum possible maximum edge on a u-v path, many queries
1Brute force
BFS per query restricted to edges <= x: O(q(n + m)).
2The observation
Re-traversal per query; an offline DSU cannot answer questions about the reachable set's contents online.
3Why it works
Node values never decrease towards the root. The set reachable from v under <= x is the leaf set of v's highest ancestor with value <= x.
Reach for it when
- +from v, using only edges <= x, ask something about the reachable set (max value, count, k-th)
- +an online version of a 'sort edges and union' offline problem
Not when
- ×only yes/no thresholds, with offline processing allowed (sort queries + DSU is simpler)
Practice
- New Roads QueriesCSESMedium
- Graph and QueriesCodeforces2600
- Qpwoeirut and VerticesCodeforces2300
- Groceries in Meteor TownCodeforces3100
Pitfalls
Misconceptions
- !it is not the MST itself: the KRT has 2n - 1 nodes and the original vertices are its leaves
Go deeper2 combinations · resources
Combinations
Kruskal Reconstruction Tree+Binary Lifting & LCA
the minimum possible maximum edge between u and v (or the first time they connect) for many pairs
- Kruskal Reconstruction Tree:
- turns each union into a node valued by the edge weight
- Binary Lifting & LCA:
- LCA queries, or jumping to the highest ancestor with value <= x
Kruskal Reconstruction Tree+Euler Tour / Tree Flattening+Segment Tree / Fenwick (BIT)
edges deleted over time, plus queries for the max value in v's current component
- Kruskal Reconstruction Tree:
- the threshold-reachable set is a subtree
- Euler Tour / Tree Flattening:
- that subtree is a contiguous leaf range
- Segment Tree / Fenwick (BIT):
- range max with point delete over the leaf order