QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100 难度: [顯示]

#1063. Lively Party and Awkward Party

统计

Little Q's birthday is coming up, and he has decided to invite some friends to his new house for a party this weekend!

He has $n$ friends in his contact list, and any two of them either know each other or do not. Little Q wants to host a lively party on Saturday and an awkward party on Sunday.

  • A lively party with liveliness $p$ invites any number of friends such that for every invited friend, there are at least $p$ friends they know who are also attending the party, and for at least one invited friend, there are exactly $p$ friends they know who are attending the party.
  • An awkward party with awkwardness $q$ invites exactly $q$ friends, and no two of them know each other.

The two parties may have overlapping participants, and some friends may be absent from both parties. Little Q likes it when the liveliness $p$ of the Saturday party and the awkwardness $q$ of the Sunday party satisfy: $\lfloor \frac{n}{p+1} \rfloor \leq q$ and $\lfloor \frac{n}{q+1} \rfloor \leq p$.

Please help Little Q find a feasible invitation plan.

Input

The input contains multiple test cases. The first line contains an integer $T$, representing the total number of test cases. Each test case is then described as follows:

The first line of each test case contains two integers $n$ and $m$, representing the total number of friends in the contact list and the number of pairs of friends who know each other, respectively.

Each of the following $m$ lines contains two positive integers $u$ and $v$, satisfying $1 \leq u \neq v \leq n$, indicating that friend $u$ and friend $v$ know each other.

Output

For each test case, output two lines describing the participants of the lively party on Saturday and the participants of the awkward party on Sunday, respectively:

The first line should first output a positive integer representing the total number of friends invited to the Saturday party, followed by the indices of the invited friends in any order.

The second line should first output a positive integer representing the total number of friends invited to the Sunday party, followed by the indices of the invited friends in any order.

If there are multiple solutions, output any one of them.

Examples

Input 1

2
6 15
1 2
1 3
1 4
1 5
1 6
2 3
2 4
2 5
2 6
3 4
3 5
3 6
4 5
4 6
5 6
8 11
1 2
2 3
1 4
3 7
4 5
5 2
2 6
6 7
5 6
5 8
6 8

Output 1

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

Subtasks

All data satisfies $1 \leq T \leq 32$ and $1 \leq m \leq 10^5$.

  • Subtask 1: (10 points) $1 \leq n \leq 500$
  • Subtask 2: (10 points) $1 \leq n \leq 700$
  • Subtask 3: (10 points) $1 \leq n \leq 900$
  • Subtask 4: (10 points) $1 \leq n \leq 1100$
  • Subtask 5: (10 points) $1 \leq n \leq 2000$
  • Subtask 6: (10 points) $1 \leq n \leq 3000$
  • Subtask 7: (10 points) $1 \leq n \leq 4500$
  • Subtask 8: (10 points) $1 \leq n \leq 6000$
  • Subtask 9: (10 points) $1 \leq n \leq 8000$
  • Subtask 10: (10 points) $1 \leq n \leq 10000$

Note: The input size for this problem is very large; please pay attention to the time required for reading the input in your code.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.