when you go forward, from any vertex (a, b) you can go into 2 other vertices: (a, a + b) or (a + b, b), but when you go backward at any step there is only one vertex to move in: (a, b - a) if b > a, or (a - b, b) if a > b
so, solution is simple bruteforce, and it works fast.
read about Euclidean algorithm.
when you go forward, from any vertex (a, b) you can go into 2 other vertices: (a, a + b) or (a + b, b), but when you go backward at any step there is only one vertex to move in: (a, b - a) if b > a, or (a - b, b) if a > b
so, solution is simple bruteforce, and it works fast.