Given an undirected graph and two vertices and , compute the minimum number of jumps needed to go from to . Here, we say that a jump between two vertices and is possible if there is a vertex adjacent to both and .
Input consists of several graphs. Every case begins with , , and , followed by pairs , with , indicating an edge between and . Suppose , , , that the vertices are numbered between 0 and , and that there are no repeated edges.
For each graph, print the minimum number of jumps to go from
to
.
If it is impossible, print “NO”.
Even if a green light is obtained, only solutions will receive the maximum score.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T12:49:45.211Z
© Jutge.org, 2006–2026.
https://jutge.org