Under construction

Still being built. Things may change

A Certain Milk Delivery List (Easy)

Interview

Time limit1sMemory limit512 MB

Summary
On a tree, each type 1 query adds 1, 2, 3, ... to successive rooms along the path from u to v; type 2 queries ask the total delivered to a room.
Level

Medium4 of 10

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

Problem

This problem is the same as "A Certain Milk Delivery List (Hard)" except for the limits on NN and QQ.

The SASA dormitory has NN rooms and N−1N-1 secret passages built to avoid the housemother's watch. The rooms are numbered 11 through NN. A secret passage connects two different rooms in both directions, and between any two rooms there is exactly one path that uses secret passages and never visits the same room twice. Taeyoung, who delivers milk, takes several orders from his seniors and delivers milk.

Each order consists of a starting room and a destination room. Taeyoung delivers milk to every room on the path from the starting room to the destination room, and delivers ii cartons of milk to the ii-th room he visits after the starting room.

Taeyoung is so busy delivering milk that he does not remember how much milk he has delivered. Write a program that finds the amount of milk delivered in real time, so that Taeyoung can report the number of cartons delivered so far. The program must handle the following two kinds of queries.

  • 1 uu vv: Taeyoung takes an order and delivers milk from room uu to room vv.
  • 2 xx: Print the total number of cartons Taeyoung has delivered to room xx so far.

Input

The first line gives the number of rooms NN.

The next N−1N-1 lines give the passages. The ii-th of these lines contains aia_i and bib_i separated by a space, meaning that room aia_i and room bib_i are connected by a secret passage.

The N+1N+1-th line gives the number of queries QQ.

The next QQ lines give the queries. The ii-th of these lines contains the ii-th query in one of the following forms.

  • A type 1 query gives ti=1t_i = 1, the starting room number uiu_i, and the destination room number viv_i, separated by spaces.
  • A type 2 query gives ti=2t_i = 2 and the number xix_i of the room whose total delivered milk must be computed so far, separated by a space.

Output

Print the results of the type 2 queries, one per line, in order.

Constraints

  • 1≤N,Q≤1 0001 \leq N, Q \leq \textbf{1 000}
  • 1≤ai,bi≤N1 \le a_i, b_i \le N (1≤i≤N−11 \le i \le N-1)
  • Between any two rooms there is exactly one path that uses secret passages and never visits the same room twice.
  • When ti=1t_i = 1, 1≤ui,vi≤N1 \le u_i, v_i \le N (1≤i≤N1 \le i \le N)
  • When ti=1t_i = 1, ui≠viu_i \ne v_i (1≤i≤N1 \le i \le N)
  • When ti=2t_i = 2, 1≤xi≤N1 \le x_i \le N
  • At least one query has ti=2t_i = 2.

Examples1

  1. Example 1

    Input
    5
    1 2
    2 3
    3 4
    2 5
    5
    1 3 5
    1 4 5
    1 1 2
    2 2
    2 5
    
    Expected output
    4
    5