Special graph#7478

Special graph

1 sekunt
64 megabaýt
Kyn

You are given a directed graph with vertices. The special thing about the graph is that each vertex has at most one outgoing edge. Your task is to answer the following two types of queries:

Giriş

First line contains a natural number (n \le 10^5) - the number of vertices in the graph. The following line contains integer numbers, -th number is next_i (0 \le next_i \le n), meaning that there is an edge from vertex to vertex next_i. If next_i = 0, assume that there is no outgoing edge from vertex . Third line contains a natural number (m \le 10^5) - the number of queries. The following contain a query each. Queries are given in the manner described above.

Çykyş

On the -th line output the answer for the -th query of type 2 a b.

Mysallar

1-nji mysal

Loading
Loading

2-nji mysal

Loading
Loading