#P6706. [COCI 2010/2011 #7] KUGLICE
[COCI 2010/2011 #7] KUGLICE
Description
You are given a directed graph where each vertex has outdegree or .
There are the following queries:
-
1 X: Given the marble start vertex , find where the marble stops. -
2 X: Delete the outgoing edge of vertex . (It is guaranteed to exist.)
Marble movement rules:
Starting from the initial vertex, follow outgoing edges until reaching a vertex whose outdegree is .
Input Format
The first line contains a positive integer , the number of vertices in the graph.
The second line contains positive integers. The -th number is the index of the vertex that the outgoing edge of points to; if it is , then the edge does not exist.
The next line contains a positive integer , the number of queries.
The next lines each contain one query in one of the formats above.
Output Format
For each query of type , 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 of the testdata, .
Notes
This problem is worth points.
Translated from COCI2010-2011 CONTEST #7 T5 KUGLICE。
Translated by ChatGPT 5
京公网安备 11011102002149号