#P8097. [USACO22JAN] Farm Updates G
[USACO22JAN] Farm Updates G
Problem Description
Farmer John runs a total of farms (), numbered . Initially, there are no roads connecting these farms, and every farm is actively producing milk.
Because the economy is always changing, Farmer John needs to modify his farms according to update operations (). There are three possible types of updates:
-
(D x)Deactivate an active farm , so it no longer produces milk. -
(A x y)Add a road between two active farms and . -
(R e)Remove the -th road that was added earlier ( is the first road that was added).
A farm is called a "relevant" farm if it is actively producing milk, or it can reach another active farm through a sequence of roads. For each farm , compute the largest () such that farm is relevant after the -th update.
Input Format
The first line of input contains and . The following lines each contain one update operation in one of the following formats:
D x
A x y
R e
The input guarantees that for updates of type R, does not exceed the number of roads that have already been added, and no two updates of type R have the same value of .
Output Format
Output lines, each containing an integer in the range .
5 9
A 1 2
A 2 3
D 1
D 3
A 2 4
D 2
R 2
R 1
R 3
7
8
6
9
9
Hint
[Sample Explanation]
In this example, the roads , , and are removed in this order.
-
Farm is relevant before the road is removed.
-
Farm is relevant before the road is removed.
-
Farm is relevant before the road is removed.
-
Farms and are still active after all updates are finished. So they remain relevant all the time, and both of their outputs should be .
[Constraints]
-
Test cases 2-5 satisfy and .
-
Test cases 6-20 have no additional constraints.
Translated by ChatGPT 5