#P14606. [NWRRC 2025] Games of Chess

[NWRRC 2025] Games of Chess

题目描述

There are nn friends and nn houses in Chess City, both numbered from 11 to nn, where friend ii lives in house ii. The houses are connected by mm bidirectional roads, forming a connected network.

Chess City also has nn virtual chess clubs, numbered from 11 to nn. Each friend must choose exactly one club to join. These choices do not need to be distinct, so some clubs might not have any members.

When friend ii hosts a chess party, it is attended by every friend who belongs to the same club as friend ii and lives in a house directly connected to house ii by a road. The party is considered successful\textit{successful} if the total number of attendees, including friend ii, is even; in this case, they can all play chess simultaneously.

Choose a club for each friend so that every friend's party is successful, or report that it is impossible.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and mm, denoting the number of houses and the number of roads (2n1052 \le n \le 10^5; n1m2105n - 1 \le m \le 2 \cdot 10^5).

Each of the following mm lines contains two integers uu and vv, describing a bidirectional road between houses uu and vv (1u,vn1 \le u, v \le n; uvu \ne v). No two houses are connected by more than one road. It is possible to get from any house to any other one using the roads.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5, and the sum of mm over all test cases does not exceed 21052 \cdot 10^5.

输出格式

For each test case, print a single integer 1-1 if it is impossible to assign a chess club to each friend so that every friend's party is successful.

Otherwise, print nn integers c1,c2,,cnc_1, c_2, \ldots, c_n, where cic_i is the number of the chess club that friend ii should join (1cin1 \le c_i \le n). If there are multiple answers, print any of them.

3
2 1
1 2
3 3
1 2
2 3
3 1
8 10
1 2
1 4
1 7
5 2
5 4
5 7
5 3
2 6
2 8
6 8
1 1
-1
3 3 6 6 6 2 6 2