CF1070L.Odd Federalization

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Berland has nn cities, some of which are connected by roads. Each road is bidirectional, connects two distinct cities and for each two cities there's at most one road connecting them.

The president of Berland decided to split country into rr states in such a way that each city will belong to exactly one of these rr states.

After this split each road will connect either cities of the same state or cities of the different states. Let's call roads that connect two cities of the same state "inner" roads.

The president doesn't like odd people, odd cities and odd numbers, so he wants this split to be done in such a way that each city would have even number of "inner" roads connected to it.

Please help president to find smallest possible rr for which such a split exists.

输入格式

The input contains one or several test cases. The first input line contains a single integer number tt — number of test cases. Then, tt test cases follow. Solve test cases separately, test cases are completely independent and do not affect each other.

Then tt blocks of input data follow. Each block starts from empty line which separates it from the remaining input data. The second line of each block contains two space-separated integers nn , mm ( 1n20001 \le n \le 2000 , 0m100000 \le m \le 10000 ) — the number of cities and number of roads in the Berland. Each of the next mm lines contains two space-separated integers — xix_i , yiy_i ( 1xi,yin1 \le x_i, y_i \le n ; xiyix_i \ne y_i ), which denotes that the ii -th road connects cities xix_i and yiy_i . Each pair of cities are connected by at most one road.

Sum of values nn across all test cases doesn't exceed 20002000 . Sum of values mm across all test cases doesn't exceed 1000010000 .

输出格式

For each test case first print a line containing a single integer rr — smallest possible number of states for which required split is possible. In the next line print nn space-separated integers in range from 11 to rr , inclusive, where the jj -th number denotes number of state for the jj -th city. If there are multiple solutions, print any.

输入输出样例

  • 输入#1

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

    输出#1

    1
    1 1 1 1 1 
    2
    2 1 1 1 1 1
    
首页