Problem 3534 · Hard

Path Existence Queries in a Graph II

Two nodes share an edge when their values differ by at most maxDiff. For each query, find the fewest edges between two nodes, or -1 if they are not connected.

Open the interactive visualisation