And the first case is that G is closer to A than G2,

then the route can look like this.

In this case, we can actually refill at G instead of G1,

and then we will have another optimal route

because it has the same number of refills and G is reachable from A.

And G2 is actually reachable from G,

because it was reachable from G1, but G is closer to G2 than G1.

So this is a correct route, and in this case, our lemma is proved.

And the second case is when G2 is actually closer to A than G, and

then the route can look like this.

But in this case we can avoid refilling at G1 at all and

refill at G2 or even refill at G in the first place.

And then we will reduce the number of refills of our optimal route,

which is impossible.

So the second case actually contradicts our statement

that we are looking at an optimal route, and we've proved our lemma.

To recap, we consider the optimal route R with a minimum number of refills.

We denote by G1 the position of the first refill in R, and by G2,

the next stop was R, which is either a refill or the destination B.

And by G we denote the farthest refill reachable from A, and

we considered two cases.

In the first case, if G is closer than G2 to A,

we can refill at G instead of G1, and it means that refill at G is a safe move.