#P1694. [USACO19FEB] The Great Revegetation B

[USACO19FEB] The Great Revegetation B

Problem Description

A long drought has left Farmer John’s NN pastures short of grass. With the rainy season coming soon, now is the time to replant.

Farmer John has four buckets in his barn, each containing a different type of grass seed. He wants to plant exactly one type of grass in each pasture. As a dairy farmer, Farmer John wants to make sure each of his cows gets a varied diet. Each of his MM cows has two favorite pastures, and he wants to ensure that these two pastures are planted with different types of grass, so that each cow has two choices of grass. Farmer John knows that no pasture is liked by more than 33 cows.

Please help Farmer John choose the grass type for each pasture so that all cows’ needs are satisfied.

Input Format

The first line of input contains 2N1002 \leq N \leq 100 and 1M1501 \leq M \leq 150. The next MM lines each contain two integers in the range 1N1 \dots N, representing the two pastures liked by one of Farmer John’s cows.

Output Format

Output an NN-digit number, where each digit is one of 141 \ldots 4, indicating the type of grass planted in each pasture. The first digit corresponds to the grass type in pasture 11, the second digit to pasture 22, and so on. If there are multiple feasible solutions, output the smallest NN-digit number among all solutions.

5 6
4 1
4 2
4 3
2 5
1 2
1 5
12133

Hint

Translated by ChatGPT 5