#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 77 rings in the figure below, numbered from 00 to 66. In this example, there are two "critical" rings. One critical ring is ring 22. After removing this ring, the remaining rings form three chains: [1][1], [0,5,3,4][0,5,3,4], and [6][6]. Another critical ring is ring 33. After removing this ring, the remaining rings form three chains: [1,2,0,5][1,2,0,5], [4][4], and [6][6]. If we try to remove any other ring, we cannot obtain a collection of pairwise disjoint chains. For example, after removing ring 55, although we can obtain a chain like [6][6], rings 0,1,2,30,1,2,3 and 44 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 22 integers N,LN, L. NN means there are NN pairwise disjoint rings, numbered from 00 to N1N-1, as the initial ring configuration. LL is the number of operations.

  • Lines 22 to L+1L+1 each contain 11 or 22 integers, describing an operation as follows:

  1. A B means linking ring AA and ring BB together. It is guaranteed that AA and BB are different.

  2. -1 output one line: the number of critical rings in the current linked-ring configuration.

Output Format

For each operation of type 22, 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 100%100\% of the testdata, 1N,L1061 \le N, L \le 10^6.

Translated by ChatGPT 5