Gangsters in Central City
Time limit2sMemory limit256 MB
On a rooted tree, after each update marking a leaf as gangster-held, report the minimum pipes to clog and the fewest innocent houses left dry.
Problem
The sewage network of Central City is a rooted tree. The reservoir sits at the root, vertex 1, and every house sits at a leaf. Water flows from the reservoir along the pipes, which are the edges of the tree, so every house has water.
Gangsters have taken over some of the houses. You are the mayor and you want to cut the water off from every house they hold. You can clog a pipe. A house loses its water when at least one pipe on the path from the reservoir to that house is clogged.
The work has to look like an accident, so you clog as few pipes as possible. Among all the ways to clog that many pipes, you also want as few gangster free houses as possible to lose their water.
Gangsters keep moving in and out of houses. After each change, report the minimum number of pipes you have to clog, and the minimum number of gangster free houses left without water when you clog that many pipes.
Input
The first line contains two integers and , the number of vertices of the tree and the number of changes (, ).
The second line contains integers , where is the parent of vertex (). The reservoir is vertex 1 and every leaf is a house.
Each of the next lines describes one change. The line "+ v" means the gangsters take the house at vertex , and the line "- v" means they leave it. Vertex is always a leaf. At the start no house is held. The changes are consistent: the gangsters never take a house they already hold, and never leave a house they do not hold.
Output
Print lines, two integers on each line. On the -th line print the minimum number of pipes you have to clog after the -th change, and the minimum number of houses that hold no gangsters and end up without water when you clog that many pipes. If no house is held after a change, print 0 0.