Pregunta de entrevista de Oracle

cyclic graph question from leetcode