#P5870. Democracy Pretender
Democracy Pretender
Democracy Pretender
You are the president of a society with N people (numbered from 1 to N) and M wishes. Each wish is described by a directed pair X → Y (where X and Y are integers), meaning that person X wishes person Y to be unhappy.
In this society, a person X is happy if and only if at least one of the wishes made by person X is fulfilled. Although humans are peculiar creatures – they are only happy when someone else is unhappy – you, as the president, have the magic of an elf and can choose which wishes to fulfill.
However, your goal is to pretend that your society is democratic. Instead of the common notion that at least half of the people or wishes need to be happy/fulfilled, you decree that among the M wishes, you will fulfill at least \(\lfloor M/4\rfloor + 1\) of them.
Your task is to select a valid set of wish indices to fulfill such that the number of fulfilled wishes is at least \(\lfloor M/4\rfloor + 1\). When a wish \(X \rightarrow Y\) is fulfilled, it makes person X happy because at least one of his/her wishes is satisfied, while person Y becomes unhappy.
If multiple solutions exist, you can output any one of them.
Input Format: The first line contains two integers N and M. The following M lines each contain two integers X and Y, representing a wish.
Output Format: First, output an integer K (the number of wishes you choose to fulfill), followed by a line with K space-separated integers representing the indices (1-indexed) of the wishes you decided to fulfill.
inputFormat
The first line contains two integers N and M (1 ≤ N, M ≤ 105). Each of the next M lines contains two integers X and Y (1 ≤ X, Y ≤ N) indicating a wish that person X wants person Y to be unhappy.
outputFormat
Output two lines. The first line should contain an integer K, the number of wishes you fulfill. The second line should contain K space-separated integers, which are the 1-indexed positions of the wishes you choose to fulfill. It must hold that \(K \geq \lfloor M/4 \rfloor + 1\).
sample
3 4
1 2
2 3
3 1
1 3
2
1 2
</p>