Pregunta de entrevista de Atlassian

A easy-medium problem involving DFS.