QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 32 MB Points totaux : 120

#17016. KUGLICE

Statistiques

Mirko 和 Slavko 喜欢玩弹珠。在一个令人兴奋的星期五,Mirko 想出了一个弹珠游戏,并想展示给 Slavko。

在游戏中,Mirko 构建了一个有向图,其中所有顶点的出度最多为 $1$(即每个顶点最多只有一条出边)。然后,他在其中一个顶点上放一颗弹珠。每当弹珠位于某个顶点 $X$ 时,如果存在出边,弹珠就会移动到通过该单向边连接的相邻顶点。弹珠的移动会一直持续,直到到达一个没有出边的顶点并停在那里。如果永远无法到达这样的顶点,弹珠也可能会在图中无限循环移动。

为了确保 Slavko 理解游戏规则,Mirko 将提出一系列询问。询问的类型如下:

  • 1 X — 如果将弹珠放在顶点 $X$ 上,它最终会停在哪个顶点?(除非弹珠陷入循环)
  • 2 X — 删除顶点 $X$ 的出边(保证该出边一定存在)。

注意:询问是按顺序执行的,并且是累积的(一个操作会影响后续操作)。

输入格式

第一行包含一个正整数 $N$($1 \le N \le 300\,000$),表示图中的顶点数。

第二行包含恰好 $N$ 个由单个空格分隔的非负整数,其中第 $i$ 个位置的数字表示从索引为 $i$ 的顶点出发的出边的终点顶点索引。值为 $0$ 表示索引为 $i$ 的顶点没有出边。

第三行包含一个正整数 $Q$($1 \le Q \le 300\,000$),表示询问的数量。

接下来的 $Q$ 行包含上述格式的询问。

输出格式

对于每个类型为 1 的询问,输出一行,包含弹珠停止的顶点索引,输出顺序与询问执行顺序一致。如果弹珠永远不会停止,则输出 CIKLUS

样例

输入样例 1

3
2 3 1
7
1 1
1 2
2 1
1 2
1 1
2 2
1 2

输出样例 1

CIKLUS
CIKLUS
1
1
2

输入样例 2

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

输出样例 2

1
CIKLUS
4
3

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.