CF1916F.Group Division
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In the 31 st lyceum, there were two groups of olympiad participants: computer science and mathematics. The number of computer scientists was n1 , and the number of mathematicians was n2 . It is not known for certain who belonged to which group, but it is known that there were friendly connections between some pairs of people (these connections could exist between a pair of people from the same group or from different groups).
The connections were so strong that even if one person is removed along with all their friendly connections, any pair of people still remains acquainted either directly or through mutual friends.
† More formally, two people (x,y) are acquainted in the following case: there are people a1,a2,…,an ( 1≤ai≤n1+n2 ) such that the following conditions are simultaneously met:
∙ Person x is directly acquainted with a1 .
∙ Person an is directly acquainted with y .
∙ Person ai is directly acquainted with ai+1 for any ( 1≤i≤n−1 ).
The teachers were dissatisfied with the fact that computer scientists were friends with mathematicians and vice versa, so they decided to divide the students into two groups in such a way that the following two conditions are met:
∙ There were n1 people in the computer science group, and n2 people in the mathematics group.
∙ Any pair of computer scientists should be acquainted (acquaintance involving mutual friends, who must be from the same group as the people in the pair, is allowed), the same should be true for mathematicians.
Help them solve this problem and find out who belongs to which group.
输入格式
Each test consists of several test cases. The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases. Then follows the description of the test cases.
The first line of each test case contains three integers n1 , n2 , and m ( 1≤n1,n2≤2000 , 1≤m≤5000 ). n1 , n2 are the sizes of the two groups described in the problem, and m is the number of friendly connections initially.
The following m lines describe the friendly connections: in the i -th ( 1≤i≤m ) line, a pair of numbers (a,b) is given, which means that the person with number a is friends with the person with number b (and vice versa).
It is guaranteed that for each test case, all friendly connections are distinct.
It is guaranteed that the sum of n1+n2 for all test cases does not exceed 2000 , and the sum of m for all test cases does not exceed 5000 .
It is also guaranteed that for each test case, a solution exists.
If there are several answers, print any of them.
输出格式
For each test case, output two lines.
In the first line, output n1 distinct numbers ai ( 1≤ai≤n1+n2 ) — the people belonging to the first group.
In the second line, output n2 distinct numbers bi ( 1≤bi≤n1+n2 ) — the people belonging to the second group.
All numbers must be distinct.
If there are several possible answers, print any one.
输入输出样例
输入#1
3 1 2 3 2 3 1 3 1 2 1 4 7 2 5 3 4 2 4 1 2 3 5 4 5 1 5 3 3 7 1 2 1 6 2 3 2 5 3 4 4 5 4 6
输出#1
3 1 2 5 1 2 3 4 4 5 6 1 2 3
说明/提示
Consider the third test case. The division into groups looks as follows:
The students selected as computer scientists are colored in green, and those selected as mathematicians are colored in blue.Consider all pairs of computer scientists and how they are acquainted:
Pairs (4,5),(4,6) are directly acquainted.
Pair (5,6) is acquainted through the computer scientist with number 4 .
Consider all pairs of mathematicians and how they are acquainted:
Pairs (1,2),(2,3) are directly acquainted.
Pair (1,3) is acquainted through the mathematician with number 2 .
We conclude that any pair of people belonging to the same group is acquainted with each other, thus the division into two groups is correct.