#P12204. Kernel Committee Selection
Kernel Committee Selection
Kernel Committee Selection
Given N persons and M directed relationships, where each relationship is of the form \((a, b)\) indicating that \(b\) makes \(a\) angry, you are asked to select a committee (i.e. a kernel) that satisfies the following conditions:
- For any two persons in the committee, there is no direct anger relationship between them. In other words, for any two committee members \(u\) and \(v\), neither \((u,v)\) nor \((v,u)\) is present.
- For every person not in the committee, there exists at least one committee member who makes that person angry. Formally, for every person \(v \notin S\) (where \(S\) is the committee), there exists some \(u \in S\) such that the relationship \((v,u)\) exists.
It is guaranteed that the graph of anger relationships does not contain any odd-length anger cycle. An odd-length anger cycle is defined as a sequence \[ x_1\to x_2\to \cdots \to x_k \to x_1 \] with odd \(k\) (and with the convention \(x_{k+1}=x_1\)), where for each \(i\), \(x_{i+1}\) makes \(x_i\) angry.
Your task is to construct a valid committee satisfying the above conditions, or determine that no such committee exists.
inputFormat
The first line contains two integers \(N\) and \(M\), representing the number of persons and the number of directed relationships.
The following \(M\) lines each contain two integers \(a\) and \(b\), indicating that there is a relationship \((a, b)\), meaning that person \(b\) makes person \(a\) angry. It is assumed that the persons are numbered from 1 to \(N\).
outputFormat
If a valid committee exists, output the committee members' numbers in increasing order in a single line, separated by spaces. If there are multiple solutions, any one is acceptable. If no valid committee exists, output -1.
sample
3 3
1 2
2 3
3 1
-1
</p>