CF1776F.Train Splitting

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

There are nn big cities in Italy, and there are mm train routes between pairs of cities. Each route connects two different cities bidirectionally. Moreover, using the trains one can reach every city starting from any other city.

Right now, all the routes are operated by the government-owned Italian Carriage Passenger Company, but the government wants to privatize the routes. The government does not want to give too much power to a single company, but it also does not want to make people buy a lot of different subscriptions. Also, it would like to give a fair chance to all companies. In order to formalize all these wishes, the following model was proposed.

There will be k2k \ge 2 private companies indexed by 1,2,,k1, \, 2, \, \dots, \, k . Each train route will be operated by exactly one of the kk companies. Then:

  • For any company, there should exist two cities such that it is impossible to reach one from the other using only routes operated by that company.
  • On the other hand, for any two companies, it should be possible to reach every city from any other city using only routes operated by these two companies.

Find a plan satisfying all these criteria. It can be shown that a viable plan always exists. Please note that you can choose the number kk and you do not have to minimize or maximize it.

输入格式

Each test contains multiple test cases. The first line contains an integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases. The descriptions of the tt test cases follow.

The first line of each test case contains two integers nn and mm ( 3n503 \le n \le 50 , n1mn(n1)/2n-1 \le m \le n(n-1)/2 ) — the number of cities and the number of train routes.

The next mm lines contain two integers uiu_i and viv_i each ( 1ui,vin1 \le u_i, v_i \le n , uiviu_i \ne v_i ) — the ii -th train route connects cities uiu_i and viv_i .

It is guaranteed that the routes connect mm distinct pairs of cities. It is guaranteed that using the trains one can reach every city starting from any other city.

The sum of the values of nn over all test cases does not exceed 50005000 .

输出格式

For each test case, on the first line print an integer kk ( 2km2 \le k \le m ) — the number of companies in your plan; on the second line print mm integers c1,c2,,cmc_1, \, c_2, \, \dots, \, c_m ( 1cik1 \le c_i \le k ) — in your plan company cic_i operates the ii -th route.

If there are multiple valid plans, you may print any of them.

输入输出样例

  • 输入#1

    2
    5 9
    1 2
    1 3
    1 4
    1 5
    2 3
    2 4
    2 5
    3 4
    3 5
    3 3
    1 2
    3 1
    2 3

    输出#1

    4
    1 2 3 1 4 2 2 4 3
    3
    2 3 1

说明/提示

In the first test case, the output is illustrated in the following picture, where different colors correspond to different companies (blue for 11 , red for 22 , green for 33 , and yellow for 44 ):

If we consider, for example, only companies 22 and 33 , we can see that from any city it is possible to reach every other city (picture on the left below). However, if we restrict to company 22 alone, it becomes impossible to reach city 55 from city 11 (picture on the right).

In the second test case, the output is illustrated in the following picture:

首页