VivoParc Animal Assignment
Time limit1sMemory limit128 MB
Assign one of four species to each of up to 100 enclosures so visible pairs differ, and print the lexicographically smallest valid assignment.
- Level
Medium7 of 10
- Topics
- Backtracking, Graph
- Solved
- No attempts yet
Problem
VivoParc is a zoological park in Valencia. It recently opened a new area, a large flat savanna grassland divided into several enclosures.
Each new enclosure has to hold one animal of one of four species: lions, leopards, tigers, and panthers. These animals are very territorial, so no animal may see another animal of its own species from its enclosure. The park manager sent the visibility data between the enclosures, so assign one species to every enclosure while respecting that data. When the assignment is finished, no enclosure may be left without a species.
Input
The first line contains the number of enclosures . ()
Every line from the second one to the end of the file holds one visibility restriction. 1-3 means that animals in enclosure 1 can see animals in enclosure 3, and animals in enclosure 3 can see animals in enclosure 1. The manager is not a very well organized person, so the same restriction may appear several times, sometimes with the two numbers swapped.
At least one assignment satisfying every restriction exists.
Output
Print one line per enclosure with the enclosure number and the species assigned to it, separated by a space. Species 1 is the lion, 2 the leopard, 3 the tiger, and 4 the panther. Enclosure numbers appear in increasing order from 1 to .
Several assignments can satisfy the restrictions. So that the answer is unique, print the assignment whose species sequence , read from enclosure 1 to enclosure , is lexicographically smallest. That is, make as small as possible, then keep it fixed and make as small as possible, and continue the same way to the last enclosure.