Pregunta de entrevista de Amazon

Graph Question - convert the graph to a tree (medium)