Each edge of the cube is 20cm. If it stayed on the edges it would need to walk on 3 edges for a total distance of 3 x 20 = 60 cm.
If it walked diagonally across the front face and then one edge it would travel:
Diagonal = sqrt(20^2 + 20^2) = 28.28
Total distance waling a diagonal and then an edge = 28.28 + 20 = 48.28 cm
The shortest distance would be diagonally across the front face then the edge to point B and the distance would be 48.28 cm.