Build the village guard post part by part: 18 levels of topological sort, Kahn's algorithm, dependency graphs and cycle detection.
Many things must happen in a certain order: a module is built after its dependencies, a course is taken after its prerequisites, a package is installed after what it needs. Topological sort produces that order. The rule (Kahn's algorithm): repeatedly take a node whose dependencies are all already placed. On this pos ronda every node is one part of the building, and the parts that are ready light up: tap them one by one until everything stands.
When dependencies form a loop (a needs b, b needs c, c needs a), there is no valid order: every node waits for another forever. This is a circular dependency, a real bug in module imports and build systems. Kahn's algorithm detects it: if at some point no node is ready while nodes still remain, the rest are locked in a cycle. Place everything you can first, then press "Cycle!" when stuck.
A cycle needn't swallow the whole graph: it can hide among healthy nodes. Strategy: run Kahn as usual, placing every node that becomes ready. If at the end some nodes remain with none ready, those are the ones locked in a cycle. Place what you can first, then declare a cycle for the rest.
And more, 18 levels in all.