Pregunta de entrevista de Google

Graphs and DP mostly with some twists