Under construction

Still being built. Things may change

Gangsters in Central City

Time limit2sMemory limit256 MB

Summary
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.
Level

Medium7 of 10

Topics
Tree, Greedy, DFS
Solved
No attempts yet

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 nn and qq, the number of vertices of the tree and the number of changes (2≤n≤1000002 \le n \le 100000, 1≤q≤1000001 \le q \le 100000).

The second line contains n−1n - 1 integers p2,p3,…,pnp_2, p_3, \dots, p_n, where pip_i is the parent of vertex ii (1≤pi<i1 \le p_i < i). The reservoir is vertex 1 and every leaf is a house.

Each of the next qq lines describes one change. The line "+ v" means the gangsters take the house at vertex vv, and the line "- v" means they leave it. Vertex vv 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 qq lines, two integers on each line. On the ii-th line print the minimum number of pipes you have to clog after the ii-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.

Examples3

  1. Example 1

    Input
    7 6
    1 2 1 3 3 3
    + 4
    + 5
    + 6
    + 7
    - 6
    - 5
    
    Expected output
    1 0
    2 0
    2 1
    2 0
    2 1
    2 0
    
  2. Example 2

    Input
    2 3
    1
    + 2
    - 2
    + 2
    
    Expected output
    1 0
    0 0
    1 0
    
  3. Example 3

    Input
    10 6
    1 2 3 3 3 3 3 3 3
    + 4
    + 10
    - 4
    + 5
    - 10
    - 5
    
    Expected output
    1 0
    1 5
    1 0
    1 5
    1 0
    0 0