QOJ.ac

QOJ

时间限制: 2 s 内存限制: 512 MB 总分: 100

#11087. 核骑士

统计

比武大赛是一项中世纪竞赛,参赛者骑在马上,在高速奔跑中试图用木制长矛击中对方。共有 $2n$ 名骑士参加了比武大赛,其中两个敌对家族各派出 $n$ 名骑士。骑士们到达后,每位骑士都向对方家族的一名骑士发起了决斗挑战。

核(kernel)定义为骑士的一个子集 $S$,且满足以下两个性质: $S$ 中的任何骑士都没有被 $S$ 中的另一名骑士挑战。 不在 $S$ 中的每一名骑士都被 $S$ 中的某一名骑士挑战。

给定发出的挑战集合,请找出一个核。保证核一定存在。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 100\,000$),表示每个家族的骑士人数。第一个家族的骑士编号为 $1$ 到 $n$,第二个家族的骑士编号为 $n+1$ 到 $2n$。

接下来一行包含整数 $f_1, f_2, \dots, f_n$,其中第 $k$ 个整数 $f_k$ 是骑士 $k$ 所挑战的骑士编号 ($n+1 \le f_k \le 2n$)。

接下来一行包含整数 $s_1, s_2, \dots, s_n$,其中第 $k$ 个整数 $s_k$ 是骑士 $n+k$ 所挑战的骑士编号 ($1 \le s_k \le n$)。

输出格式

在一行中输出核中骑士的编号。如果存在多个解,输出其中任意一个即可。

样例

输入 1

4
5 6 7 7
1 3 2 3

输出 1

1 2 4 8

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.