#P5361. [SDOI2019] 热闹的聚会与尴尬的聚会
[SDOI2019] 热闹的聚会与尴尬的聚会
Description
There are friends in his contact list. Any two friends either know each other or do not know each other. Xiao Q wants to hold a lively party on Saturday, and then an awkward party on Sunday.
- A party with liveliness invites any number of friends. For every friend who attends, there are at least friends that he knows also attending the party, and for at least one attending friend, there are exactly friends that he knows at the party.
- A party with awkwardness invites exactly friends, and they are pairwise not acquainted with each other.
The two parties may have overlapping participants, and it is also possible that some friends in the contact list miss both parties.
Xiao Q likes the liveliness of Saturday’s party and the awkwardness of Sunday’s party to satisfy: and .
Please help Xiao Q find a feasible invitation plan.
Input Format
The input contains multiple test cases. The first line gives an integer , which denotes the number of test cases. Then each test case follows.
For each test case, the first line gives two integers and , which denote the total number of friends in the contact list, and the number of pairs of friends who know each other.
Then lines follow. Each line gives two positive integers and , satisfying , meaning that friend and friend know each other.
Output Format
For each test case, output two lines, describing the participant list of Saturday’s lively party and Sunday’s awkward party, respectively.
The first line first outputs a positive integer, indicating how many friends are invited to the Saturday party, and then outputs several distinct integers in any order, describing which friends are invited.
The second line first outputs a positive integer, indicating how many friends are invited to the Sunday party, and then outputs several distinct integers in any order, also describing which friends are invited on Sunday.
If there are multiple valid solutions, you may output any one of them.
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
6 1 2 3 4 5 6
1 4
8 1 2 3 4 5 6 7 8
4 8 4 7 2
Hint
Constraints
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): .
For all test points, it holds that and .
Notes
The input size of this problem is very large. Please pay attention to the time needed for input in your code.
Explanation
Thanks to @81179332_ for providing the spj!
Translated by ChatGPT 5
京公网安备 11011102002149号