[Community Puzzle] orDer oF succeSsion

I didn’t find a topic for this puzzle https://www.codingame.com/training/easy/order-of-succession, I’m not sure if I was supposed to create one or not.

I can’t seem to figure out how to solve this one. The title strongly hints about using a DFS algorithm, but DFS doesn’t account for ordering the children of a certain person as it is asked here.

Any hints? (I’m working in C++ btw)

Yes, the trick is to sort the children when you add them in the queue.