#USACOC2222B. Farm Updates
Farm Updates
Description
Farmer John operates a collection of farms, convenientlynumbered . Initially, there are no roads connecting these farms toeach-other, and each farm is actively producing milk.
Due to the dynamic nature of the economy, Farmer John needs to make changes tohis farms according to a series of update operations. Update operations come in three possible forms:
- (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 previously added ( is the firstroad that was added).
A farm that is actively producing milk, or that can reach another activefarm via a series of roads, is called a "relevant" farm. For each farm ,please calculate the maximum such that is relevantafter the -th update.
Input Format
The first line of input contains and . The next lines each contain an update of one of the following forms:
D x
A x y
R e
It is guaranteed that for updates of type R, is at most the number of roadsthat have been added so far, and no two updates of type R have the same value of.
Output Format
Please 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
5 9
A 1 2
A 2 3
D 1
D 3
A 2 4
D 2
R 2
R 1
R 3
Scoring
- Tests 2 through 5 satisfy ,
- Test cases 6 through 20 satisfy no additional constraints.
Problem Credit
Problem credits: Benjamin Qi