Fox And Names
MediumRating 1600CodeforcesShortest Paths & Topological Sort
Approach hintTry it first, then revealHide
Compare each adjacent pair of names: the first differing letter gives one edge between letters, and a name followed by its own proper prefix is impossible at once. Topologically sort the 26 letters and report a cycle as impossible.