Pergunta de entrevista da empresa Uber

Question on the shortest path but a little twisted.