#P14606. [NWRRC 2025] Games of Chess
[NWRRC 2025] Games of Chess
题目描述
There are friends and houses in Chess City, both numbered from to , where friend lives in house . The houses are connected by bidirectional roads, forming a connected network.
Chess City also has virtual chess clubs, numbered from to . 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 hosts a chess party, it is attended by every friend who belongs to the same club as friend and lives in a house directly connected to house by a road. The party is considered if the total number of attendees, including friend , 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 (). The description of the test cases follows.
The first line of each test case contains two integers and , denoting the number of houses and the number of roads (; ).
Each of the following lines contains two integers and , describing a bidirectional road between houses and (; ). 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 over all test cases does not exceed , and the sum of over all test cases does not exceed .
输出格式
For each test case, print a single integer if it is impossible to assign a chess club to each friend so that every friend's party is successful.
Otherwise, print integers , where is the number of the chess club that friend should join (). 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
京公网安备 11011102002149号