#P6165. [IOI 2012] rings
[IOI 2012] rings
Description
In Leonardo’s manuscript "Codex Atlanticus", an early and complex parachute was described. Leonardo’s parachute is a pyramid-shaped wooden frame covered with sewn cloth.
Linked rings
A free-fall skydiver, Adrain Nicholas (Ai Zhun Ni Gu La Si), tested Leonardo’s design five hundred years later. In this test, a modern lightweight frame was used to attach Leonardo’s parachute to a human body. We want to use linked rings, which provide hooks for the sewn cloth. Rings can be linked together easily, and each ring can be opened or closed. Linked rings can form a special shape called a "chain". A "chain" is a sequence of linked rings, where each ring can be linked to (at most two) neighbors. However, this sequence must have a beginning and an end (these two rings can each be linked to only one other ring), as shown in the figure below.

Other linking shapes are also possible, because one ring can be linked to 3 or more rings. We say a ring is "critical" if, after we open it and remove this ring, the remaining rings form a collection of pairwise disjoint chains (or no rings remain).
Example
Consider the rings in the figure below, numbered from to . In this example, there are two "critical" rings. One critical ring is ring . After removing this ring, the remaining rings form three chains: , , and . Another critical ring is ring . After removing this ring, the remaining rings form three chains: , , and . If we try to remove any other ring, we cannot obtain a collection of pairwise disjoint chains. For example, after removing ring , although we can obtain a chain like , rings and do not form a chain.

Task
Given a configuration of linked rings, your program must compute the number of critical rings in it.
Input Format
-
The first line contains integers . means there are pairwise disjoint rings, numbered from to , as the initial ring configuration. is the number of operations.
-
Lines to each contain or integers, describing an operation as follows:
-
A Bmeans linking ring and ring together. It is guaranteed that and are different. -
-1output one line: the number of critical rings in the current linked-ring configuration.
Output Format
For each operation of type , output one line: the number of critical rings in the current linked-ring configuration at that time.
100 84
30 79
26 63
96 30
17 97
33 63
73 25
17 7
96 48
80 6
3 34
51 48
33 37
89 7
72 65
51 54
49 37
45 72
50 39
95 89
3 55
25 0
2 54
10 91
59 2
29 46
0 40
95 68
69 45
87 68
49 38
20 69
87 15
35 39
59 47
38 62
91 19
35 70
83 19
28 20
70 24
36 55
75 36
28 12
53 29
12 16
75 84
40 85
27 53
58 62
88 84
44 27
76 24
58 22
8 44
94 15
14 94
5 83
31 85
90 5
88 42
81 47
76 67
82 80
31 93
14 74
42 98
99 82
71 8
98 92
18 22
81 52
99 23
41 67
74 1
93 56
4 52
1 86
92 60
56 66
18 61
16 57
43 23
4 64
-1
100
Hint
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号