Under construction

Still being built. Things may change

Water Tanks of Seongdae Country

Time limit1sMemory limit256 MB

Summary
A tree of water tanks rooted at a capital. Adding water at city A adds 1,2,3,... along the root-to-A path. Answer queries about how much water a given city currently holds.
Level

Hard8 of 10

Topics
Tree, DFS, Prefix sum, Implementation
Solved
No attempts yet

Problem

Seongdae Country has one water tank in each city to prepare for droughts. All the tanks are connected and form a tree whose root is the capital. The country survived a drought using the water in the tanks, but as a result every tank is now empty.

The country's water management system is unusual: water is always added in the following way.

When water is to be added at city A, 1L, 2L, ... are added in order along the path from the capital to city A, starting at the capital. Thus (the number of cities from the capital to city A) L is added to city A.

For example, if the tanks are connected as in the figure below and we "add water at city 4," then 1L is added to city 1 and 2L to city 4. If we "add water at city 5," then 1L is added to city 1, 2L to city 2, and 3L to city 5.

Gyun-gwan, who manages the water tanks of Seongdae Country, wants to know how many liters of water are stored in any city whenever he gets curious. Write a program to help him.

Input

The first line gives the number of cities in Seongdae Country N (1 ≤ N ≤ 200,000) and the number of the capital C (1 ≤ C ≤ N), separated by a space.

The next N-1 lines each give a pair of connected cities x, y, separated by a space (1 ≤ x, y ≤ N, x ≠ y). The connections are guaranteed to form a tree. Line N+1 gives the number of queries Q (1 ≤ Q ≤ 200,000). Then Q lines follow, each containing a query. Each query is one of two types:

  • 1 A : add water at city A.
  • 2 A : print how much water is currently stored in city A.

In both cases 1 ≤ A ≤ N holds.

Output

For every query starting with 2, print the result on its own line.

Examples1

  1. Example 1

    Input
    7 1
    1 2
    1 3
    1 4
    2 5
    4 6
    4 7
    8
    1 6
    2 1
    2 4
    2 6
    1 1
    2 1
    2 4
    2 6
    
    Expected output
    1
    2
    3
    2
    2
    3