QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 512 MB Points totaux : 100

#10948. 岛屿

Statistiques

在朝鲜半岛南部的海域上有两座拥有凸多边形海岸线的孪生岛屿。每座岛屿的海岸线上各有 $n$ 个村庄。所有村庄的编号均为 $1$ 到 $n$。这些编号是随机分配给村庄的,与它们的地理位置无关。岛屿海岸线上按顺时针方向排列的村庄编号序列称为海岸线序列。若将村庄视为点,则按海岸线序列顺序连接所有村庄的闭合折线构成了凸多边形的边界。

在两座岛屿的村庄代表会议上,他们决定在每座岛屿内部各修建一条道路,需满足以下三个条件:

  1. 每条道路恰好经过每个岛屿的所有村庄各一次。
  2. 每条道路均不自交。
  3. 两座岛屿的道路序列相同,其中道路序列是指从起点到终点沿道路经过的村庄编号序列。

例如,假设每座岛屿各有 6 个村庄,两座岛屿的海岸线序列分别为 $(1, 5, 2, 4, 6, 3)$ 和 $(3, 4, 5, 2, 6, 1)$。那么,道路序列为 $(3, 1, 6, 4, 5, 2)$ 的两条道路满足上述条件。如下图所示。如果两个海岸线序列为 $(1, 2, 3, 4, 5)$ 和 $(1, 3, 5, 2, 4)$,则不存在满足上述条件的道路序列。

给定两座岛屿的海岸线序列,请编写一个程序,找出满足上述条件的道路序列(如果存在)。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($5 \le n \le 100,000$),表示每座岛屿的村庄数量。村庄编号为 $1$ 到 $n$。接下来的两行,每行包含 $n$ 个整数,分别代表每座岛屿的海岸线序列。

输出格式

程序将结果写入标准输出。输出仅一行。如果存在满足上述条件的道路序列,则输出该序列的 $n$ 个整数;否则输出 $-1$。如果存在多个解,输出其中任意一个即可。

样例

样例输入 1

6
1 5 2 4 6 3
3 4 5 2 6 1

样例输出 1

3 1 6 4 5 2

样例输入 2

5
1 2 3 4 5
1 3 5 2 4

样例输出 2

-1

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.