#P6706. [COCI 2010/2011 #7] KUGLICE

[COCI 2010/2011 #7] KUGLICE

Description

You are given a directed graph where each vertex has outdegree 00 or 11.

There are the following queries:

  1. 1 X: Given the marble start vertex XX, find where the marble stops.

  2. 2 X: Delete the outgoing edge of vertex XX. (It is guaranteed to exist.)

Marble movement rules:

Starting from the initial vertex, follow outgoing edges until reaching a vertex whose outdegree is 00.

Input Format

The first line contains a positive integer nn, the number of vertices in the graph.

The second line contains nn positive integers. The ii-th number is the index of the vertex that the outgoing edge of ii points to; if it is 00, then the edge does not exist.

The next line contains a positive integer QQ, the number of queries.

The next QQ lines each contain one query in one of the formats above.

Output Format

For each query of type 11, output the index of the vertex where the marble stops, in order, one per line.

If the marble never stops, output CIKLUS.

3
2 3 1
7
1 1
1 2
2 1
1 2
1 1
2 2
1 2
CIKLUS
CIKLUS
1
1
2
5
0 3 5 3 4
6
1 1
1 2
2 4
1 2
2 3
1 2
1
CIKLUS
4
3

Hint

Constraints

For 100%100\% of the testdata, 1n,Q3×1051 \le n,Q \le 3 \times 10^5.

Notes

This problem is worth 120120 points.

Translated from COCI2010-2011 CONTEST #7 T5 KUGLICE。

Translated by ChatGPT 5