The Great Revegetation (Bronze)
InterviewTime limit2sMemory limit512 MB
Assign each of N pastures one of 4 grass types so that every listed pair differs, choosing the lexicographically smallest N-digit answer.
- Level
Medium5 of 10
- Topics
- Graph, Greedy, Backtracking, Implementation
- Solved
- No attempts yet
Problem
A lengthy drought has left Farmer John's pastures with no grass at all. With the rainy season arriving soon, the time has come to "revegetate."
In Farmer John's shed there are four buckets, each holding a different type of grass seed. He wants to sow each pasture with one of these types of seeds. As a dairy farmer, Farmer John wants his cows to have a varied diet. Each of his cows has two favorite pastures, and different types of grass must be planted in those two pastures so that every cow can choose between two types of grass. Farmer John knows that no pasture is a favorite of more than cows.
Help Farmer John choose a grass type for each pasture so that the nutritional needs of all cows are satisfied.
Input
The first line contains () and (). Each of the next lines contains two integers in the range , the two pastures that are the favorites of one of Farmer John's cows.
Output
Output an -digit number describing the grass type to be planted in each pasture, with each digit in the range . The first digit is the grass type for pasture , the second digit is the grass type for pasture , and so on. If there are multiple valid solutions, print only the smallest -digit number among them.