Pergunta de entrevista da empresa Uber

One question on graphs and algorithm