#P5870. [SEERC 2018] Modern Djinn
[SEERC 2018] Modern Djinn
Description
You are not a leader; you are a president. Luckily, you have a djinn that can grant your wishes. One of your wishes is to pretend that your society has democracy.
The society is simple. There are people in the society, numbered from to . Some people are “happy”, while others are ordinary (“unhappy”). Humans are very strange: people feel happy only when others are unhappy. There are wishes in total, numbered from to . means that wants to be unhappy. A person is happy if and only if at least one of their wishes is fulfilled.
Democracy is not that complicated either. Some say that to achieve democracy, you need at least half of the people to be happy (or half of the wishes to be fulfilled), but that is not entirely true. As I said, you are a good president, not a good leader. You can define democracy through the media. Therefore, among all wishes, you decide to fulfill at least wishes.
The remaining task is to choose which wishes you want to fulfill, and then the djinn will take care of everything.
Input Format
The input contains multiple test cases. The first line contains an integer , the number of test cases. The following lines give the test cases in order.
For each test case, the first line contains two positive integers and , representing the number of people in the society and the number of wishes. The next lines each contain two integers , describing a wish: wants to be unhappy.
Output Format
For each test case, output an integer on the first line, the number of wishes to be fulfilled. Output integers on the second line, the indices of the fulfilled wishes. The order does not matter.
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
1 4
1
2
2
1 4
Hint
Constraints
- There is no wish where wants to be unhappy.
- There may be multiple identical wishes where wants to be unhappy.
- For each test case, a solution is guaranteed to exist.
- Any correct solution is accepted.
Sample Explanation
In the first test case, we can fulfill at most wish; outputting any wish is valid.
In the second test case, another valid solution is to fulfill wishes , , and . At least wishes must be fulfilled.
Translated by ChatGPT 5
京公网安备 11011102002149号