CF1328D Carousel
The round carousel consists of figures of animals. Figures are numbered from to in order of the carousel moving. Thus, after the -th figure the figure with the number follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal of the -th figure equals .
You want to color each figure in one of the colors. You think that it’s boring if the carousel contains two different figures (with the distinct types of animals) going one right after another and colored in the same color.
Your task is to color the figures in such a way that the number of distinct colors used is the minimum possible and there are no figures of the different types going one right after another and colored in the same color. If you use exactly distinct colors, then the colors of figures should be denoted with integers from to .
Input
The input contains one or more test cases.
The first line contains one integer — the number of test cases in the test. Then q test cases follow. One test case is given on two lines.
The first line of the test case contains one integer — the number of figures in the carousel. Figures are numbered from 1 to n in order of carousel moving. Assume that after the n-th figure the figure 1 goes.
The second line of the test case contains integers , where is the type of the animal of the -th figure.
The sum of over all test cases does not exceed .
Output
Print answers, for each test case print two lines.
In the first line print one integer — the minimum possible number of distinct colors of figures.
In the second line print integers , where is the color of the -th figure. If there are several answers, you can print any.
Example
input
1 | 4 |
output
1 | 2 |
Translation
已知一个有 () 个点的环,点 的类型为 。现在需要给每个点进行染色,要求相邻不同类型的点的颜色不同且所用颜色数最小。输出颜色数及一种染色方案即可(颜色从 开始)。
Idea
学过离散数学都知道,环的色数至多为 ,而题目中环上相邻点若为同一类型,还可以染相同颜色,故需要颜色数至多为 。
若 个点都是同一种类型,就染一个颜色。
若要染两个及以上颜色,那么 个点至少有两种不同类型。此时染两种颜色的情况有二:1) 为偶数, 和 交替染即可;2) 为奇数,但是存在一个位置 和 的一个相邻位 , 和 的类型相同,那么将 和 取相同颜色,然后得到以 开头的奇数长度链,和 开头的偶数长度链,分别依次染色 和 。其余情况就需要染三种颜色。
Code
1 | /****************************************************************** |