#P4355. [CERC2015] Kernel Knights

[CERC2015] Kernel Knights

题目描述

Jousting is a medieval contest that involves people on horseback trying to strike each other with wooden lances while riding at high speed. A total of 2n knights have entered a jousting tournament – n knights from each of the two great rival houses. Upon arrival, each knight has challenged a single knight from the other house to a duel.

A kernel is defined as some subset S of knights with the following two properties:

• No knight in S was challenged by another knight in S.

• Every knight not in S was challenged by some knight in S.

Given the set of the challenges issued, find one kernel. It is guaranteed that a kernel always exists.

输入格式

The first line contains an integer n (1 ≤ n ≤ 100000) – the number of knights of each house. The knights from the first house are denoted with integers 1 through n, knights from the second house with integers n+1 through 2n.

The following line contains integers f1f_1, f2f_2,..., fnf_n – the k-th integer fk is the index of the knight challenged by knight k (n+1fk2n)(n+1≤ f_k ≤2n).

The following line contains integers s1s_1,s2s_2,...,sns_n – the k-th integer sk is the index of the knight challenged by knight n+k (1skn)(1≤s_k ≤n).

输出格式

Output the indices of the knights in the kernel on a single line. If there is more than one solution, you may output any one.

SPJ的格式校验较为严格,请在每个数字后面都输出一个空格,且在最后一个空格输出后请不要输出任何符号。

题目大意

骑术是一项中世纪的比赛,人们骑在马背上,在高速骑行时,试图用木制长矛互相攻击。总共有2n个骑士参加了一个激战锦标赛——来自两个主要竞争对手的N个骑士。到达后,每一个骑士都从另一个房间挑战一个骑士进行决斗。

内核被定义为骑士的一些子集,具有以下两个属性:

•S中没有骑士受到S中另一个骑士的挑战。

每一个不在S中的骑士都会受到一些S中的骑士的挑战。

考虑到所面临的一系列挑战,确定一个内核。可以保证内核始终存在。

4 
5 6 7 7 
1 3 2 3
1 2 4 8

提示

Central Europe Regional Contest 2015 Problem K