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