Pregunta de entrevista de Spectral MD

graph question from leetcode (but C++ was mandatory)