Cuckoos | 프로그래밍의 벗 PivotOJ
PivotOJ

Cuckoos

시간 제한: 2000ms메모리 제한: 1024MB출처: MOOI 2016-17 finalBOJ 30755

문제

British scientists decided to study ornithology and to investigate the life of an extraordinary kind of cuckoos. They have planted a large tree and put nn nests on it, each of the nests is inhabited with one cuckoo. The investigation involves checking if it is possible to put an extra egg to the certain nest or not.

Each egg may be raised only in some two of the nests. Each egg is defined as an unordered pair of distinct integers (x,y)(x, y). The egg (x,y)(x, y) may be raised in any of the nests xx and yy and may not be raised in any of the other nests. Notice that egg (x,y)(x, y) не is the same as the egg (y,x)(y, x).

Now we will describe the process of putting an extra egg into a given nest. Suppose we want to put the egg (x,y)(x, y) to the nest xx. If the nest xx is empty then (x,y)(x, y) remains in that nest and the process is over. Otherwise, if there is already an egg (x,p)(x, p) in the nest xx, then cuckoo puts the egg (x,y)(x, y) to the nest xx and tries to put the egg (x,p)(x, p) to the nest pp in a similar manner, and the process continues.

You task is to answer several queries of the scientists. There are three types of queries:

  1. \item(Theoretical) Will the process of putting of an egg (x,y)(x, y) to the nest xx eventually stop? Since the question is theoretical, this egg is not added actually, and the state of nests is not changed.
  2. \item(Practical) Will the process of putting of an egg (x,y)(x, y) to the nest xx eventually stop? If the answer is positive, the egg is added according to the description of the process above.
  3. \item(Theoretical) How many ordered pairs of distinct integers (x,y)(x, y) exist such that the egg (x,y)(x, y) may be put into the nest xx and the process will eventually stop? The answer for each pair is determined independently from any other pair.

입력

The first line of the input contains three integers nn, mm, qq, (2n2000002 \leq n \leq 200\,000, 0mn0 \leq m \leq n, 1q6000001 \leq q \leq 600\,000), where nn is the number of nests, mm is the number of already given eggs, qq is the number of queries.

Each of the following mm lines contains two integers xix_i, yiy_i denoting that the nest xix_i contains an egg (xi,yi)(x_i, y_i). It is guaranteed that all xix_i are distinct and that xiyix_i \ne y_i for all ii.

The following qq lines contain the queries. Queries are given in the order you have to perform them. The first number tjt_j in the query line defines the type of the query.

If tj=1t_j = 1 or tj=2t_j = 2, then there are two distinct integers xjx_j and yjy_j, defining an egg that appears in a corresponding query.

If tj=1t_j = 1, the egg should not be actually added to the current state.

If tj=2t_j = 2, the egg should be added if the process of putting an egg requires the finite number of egg transfers.

If tj=3t_j = 3, you are required to determine the number of ordered pairs (x,y)(x, y), such that the egg (x,y)(x, y) may be put to the nest xx and the process will be finite. No eggs are added to the state after this query.

출력

For each query of the first and the second type output the only word "Yes" or "No" depending on the fact the process is finite or not.

For any query of the third type output the desired number of ordered pairs.

힌트

Initial state of nests in the sample test is the following: the first nest contains the egg (1,2)(1, 2), the second nest contains the egg (2,4)(2, 4), the fifth nest contains the egg (5,1)(5, 1), the third an the fourth nests are empty.

The egg (1,2)(1, 2) may be added, despite the fact exactly the same egg is already present, this will transfer the existing egg (1,2)(1, 2) to the remaining nest.

Also, in the initial state it is possible to add any of the 10 possible eggs that exist for the tree with five nests, and each egg may be put in any of the two nests corresponding to it, such that the process will be finite. So, the answer for the second query is 20.

After the next query the egg (1,2)(1, 2) will be added, and the state of the eggs will be the following: the first nest contains an egg (1,2)(1, 2), the second also contains an egg (1,2)(1, 2), the fourth contains an egg (2,4)(2, 4) and the fifth contains an egg (5,1)(5, 1).

Now it is possible only to add the eggs (1,3)(1, 3), (2,3)(2, 3), (4,3)(4, 3) and (5,3)(5, 3), but still any of the specified eggs may be added to any of the corresponding nests, so the answer is 8.

An egg (4,2)(4, 2) may not be added to the tree in a finite number of steps, so the state of the nests won't change.

Adding an egg of (5,3)(5, 3) requires 5 egg transfers, and after that no new egg may be added in a finite number of steps.

예제

예제 1

입력
5 3 8
1 2
5 1
2 4
1 1 2
3
2 1 2
3
2 4 2
2 5 3
3
1 4 5
출력
Yes
20
Yes
8
No
Yes
0
No
코드를 제출하려면 로그인하세요.