• data structures help here?

Question related to mission Determine the Order

 

The "Determine the Order" task seems very confusing to me. Can data structures help here? For example, a system of disjoint sets?