Good Bye 2023
F
Group Division
Codeforces
2900
原题
← EG →
翻译中…

In the $31$st lyceum, there were two groups of olympiad participants: computer science and mathematics. The number of computer scientists was $n_1$, and the number of mathematicians was $n_2$. 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.

翻译中…

$^{\dagger}$ More formally, two people $(x, y)$ are acquainted in the following case: there are people $a_1, a_2, \ldots,a_n$ ($1 \le a_i \le n_1 + n_2$) such that the following conditions are simultaneously met:

翻译中…

$\bullet$ Person $x$ is directly acquainted with $a_1$.

翻译中…

$\bullet$ Person $a_n$ is directly acquainted with $y$.

翻译中…

$\bullet$ Person $a_i$ is directly acquainted with $a_{i + 1}$ for any ($1 \le i \le 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:

翻译中…

$\bullet$ There were $n_1$ people in the computer science group, and $n_2$ people in the mathematics group.

翻译中…

$\bullet$ 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.

翻译中…

Input

翻译中…

Each test consists of several test cases. The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then follows the description of the test cases.

翻译中…

The first line of each test case contains three integers $n_1$, $n_2$, and $m$ ($1 \le n_1, n_2 \le 2000$, $1 \le m \le 5000$). $n_1$, $n_2$ 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 \le i \le 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 $n_1 + n_2$ 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.

翻译中…

Output

翻译中…

For each test case, output two lines.

翻译中…

In the first line, output $n_1$ distinct numbers $a_i$ ($1 \le a_i \le n_1 + n_2$) — the people belonging to the first group.

翻译中…

In the second line, output $n_2$ distinct numbers $b_i$ ($1 \le b_i \le n_1 + n_2$) — the people belonging to the second group.

翻译中…

All numbers must be distinct.

翻译中…

If there are several possible answers, print any one.

翻译中…

Note

翻译中…

Consider the third test case. The division into groups looks as follows:

翻译中…

image

翻译中…

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.

翻译中…

样例

Input #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
Output #1
3
1 2
5
1 2 3 4
4 5 6
1 2 3
InputCopy OutputCopy
题目信息
题号
1916F
所属比赛
时间限制
1 s
内存限制
256 MB
标签
构造
DFS 及类似
图论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。