if the data might contain cycles (an employee who indirectly manages their own manager), track visited nodes: