Editorial
Build the Kruskal reconstruction tree of the original graph. The maximum bottleneck value between two vertices is represented by the value of their LCA in this tree.
Fix the final vertex . If a unit of mana at vertex is collected as the -th unit, then after collecting it the rabbit must still be able to travel from to while carrying units. Thus each mana unit can be treated as a unit-time job with a deadline.
If there are units with deadline , the greedy transition is
Equivalently, the answer is
For a query edge , the two sides of the edge are connected while the threshold is below . Therefore, on the Kruskal tree, we pull the two current components upward in decreasing order of edge values and update the answer candidates.
Processing the whole path for every query gives an solution, where is the height of the Kruskal tree. Under special condition B, the original graph is a path with random distinct capacities, so the Kruskal tree is a random Cartesian tree and has expected logarithmic height.
For the full solution, choose special vertices in the Kruskal tree so that every vertex is within edges from its nearest special ancestor. Each query is directly processed until one side reaches a special vertex.
For a fixed special vertex , all remaining queries with one endpoint are processed together. Precompute prefixes of type X operations on the chain from to the root, and simulate all type Y operations on the other endpoints by DFS. This processes one special vertex in time. Since there are special vertices, the total running time is .