Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Find the minimum spanning tree of the given graph.
Root the tree in an arbitrary node and calculate the maximum weight of the edge from each node to the chosen root.
To answer a query, find the lca between the two nodes, and find the maximum weight from each of the query nodes to their lca and compare it to the given limit.