Pregunta de entrevista de Mastercard

Graph-based problem (medium-hard) in first round