Gaggle
Time limit2sMemory limit512 MB
- Level
Not classified yet
- Solved
- No attempts yet
Gaggle
Gaggle is a start-up that replaced its management structure with mentor relations. Each Gaggler designates one other Gaggler as their mentor, and a mentor relation may or may not be symmetric. Nobody can be their own mentor.
The company wants two things. First, every Gaggler must be the mentor of exactly one other Gaggler. Second, if each Gaggler only communicates with their mentor and their mentee, any Gaggler must be able to pass information to any other Gaggler.
Lower-numbered Gagglers keep their current mentor whenever possible. Compare two valid assignments at the lowest index where they differ. If one of them gives Gaggler the current mentor, that assignment wins. Otherwise, the assignment where Gaggler gets the smaller new mentor number wins.
Given the current mentors , output the best new assignment .