#P4355. Jousting Tournament Kernel

    ID: 17601 Type: Default 1000ms 256MiB

Jousting Tournament Kernel

Jousting Tournament Kernel

In a medieval jousting tournament, there are \(2n\) knights ― \(n\) from each of two rival houses. Upon arrival, every knight challenges exactly one knight from the other house. A kernel is defined as a subset \(S\) of knights satisfying the following conditions:

  • No knight in \(S\) is challenged by another knight in \(S\), i.e. for all \(i, j \in S\), it is not true that \(i\) challenged \(j\).
  • Every knight not in \(S\) is challenged by some knight in \(S\), i.e. for every knight \(k \notin S\), there exists an \(i \in S\) such that \(i\) challenged \(k\).

It is guaranteed that such a kernel always exists. Your task is to find and output one such kernel. The knights are numbered from 1 to \(2n\). Note that since challenges only occur between knights of opposite houses, knights 1 through \(n\) belong to the first house and knights \(n+1\) through \(2n\) belong to the second house.

The conditions can be expressed in LaTeX as:

$$\text{(1) } \forall i,j\in S,\; i \text{ did not challenge } j, $$$$\text{(2) } \forall k\notin S,\; \exists i\in S \text{ such that } i \text{ challenged } k. $$

inputFormat

The input consists of three lines:

  1. The first line contains a single integer \(n\) indicating the number of knights in each house.
  2. The second line contains \(n\) space-separated integers. The \(i\)-th integer (for \(1 \le i \le n\)) is the index of the knight from the second house that the \(i\)-th knight of the first house challenges. Each such integer will lie in the range \([n+1, 2n]\).
  3. The third line contains \(n\) space-separated integers. The \(i\)-th integer (for \(1 \le i \le n\)) represents the index of the knight (from the first house) that the \(n+i\)-th knight (i.e. the \(i\)-th knight of the second house) challenges. Each such integer will lie in the range \([1, n]\).

outputFormat

Output a single line containing the indices of the knights in one kernel in ascending order, separated by a single space.

sample

1
2
1
1

</p>