A Certain Milk Delivery List (Easy)
InterviewTime limit1sMemory limit512 MB
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 and .
The SASA dormitory has rooms and secret passages built to avoid the housemother's watch. The rooms are numbered through . 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 cartons of milk to the -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 : Taeyoung takes an order and delivers milk from room to room .
- 2 : Print the total number of cartons Taeyoung has delivered to room so far.
Input
The first line gives the number of rooms .
The next lines give the passages. The -th of these lines contains and separated by a space, meaning that room and room are connected by a secret passage.
The -th line gives the number of queries .
The next lines give the queries. The -th of these lines contains the -th query in one of the following forms.
- A type 1 query gives , the starting room number , and the destination room number , separated by spaces.
- A type 2 query gives and the number 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
- ()
- Between any two rooms there is exactly one path that uses secret passages and never visits the same room twice.
- When , ()
- When , ()
- When ,
- At least one query has .