eolymp
bolt
Try our new interface for solving problems
Problems

Caves and Tunnels (Easy)

Caves and Tunnels (Easy)

After landing on Mars surface, scientists found a strange system of caves connected by tunnels. So they began to research it using remote controlled robots. It was found out that there exists exactly one route between every pair of caves. But then scientists faced a particular problem. Sometimes in the caves faint explosions happen. They cause emission of radioactive isotopes and increase radiation level in the cave. Unfortunately robots don't stand radiation well. But for the research purposes they must travel from one cave to another. So scientists placed sensors in every cave to monitor radiation level in the caves. And now every time they move robots they want to know the maximal radiation level the robot will have to face during its relocation. So they asked you to write a program that will solve their problem. \InputFile The first line of the input contains one integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}) - the number of caves. Next \textbf{N-1} lines describe tunnels. Each of these lines contains a pair of integers \textbf{a_i}, \textbf{b_i} (\textbf{1} ≤ \textbf{a_i}, \textbf{b_i} ≤ \textbf{N}) specifying the numbers of the caves connected by corresponding tunnel. The next line has an integer \textbf{Q} (\textbf{Q} ≤ \textbf{100}) representing the number of queries. The \textbf{Q} queries follow on a single line each. Every query has a form of "\textbf{C U V}", where \textbf{C} is a single character and can be either '\textbf{I}' or '\textbf{G}' representing the type of the query (quotesfor clarity only). In the case of an '\textbf{I}' query radiation level in \textbf{U}^th cave (\textbf{1} ≤ \textbf{U} ≤ \textbf{N}) is incremented by \textbf{V} (\textbf{0} ≤ \textbf{V} ≤ \textbf{10000}). In the case of a '\textbf{G}' query your program must output the maximal level of radiation on the way between caves with numbers \textbf{U}and \textbf{V} (\textbf{1} ≤ \textbf{U}, \textbf{V} ≤ \textbf{N}) after all increases of radiation ('\textbf{I}' queries) specified before current query. It is assumed that initially radiation level is \textbf{0} in all caves, and it never decreases with time (because isotopes' half-life time is much larger than the time of observations). \OutputFile For every \textbf{G} query output one line containing the maximal radiation level by itself.
Time limit 1 second
Memory limit 64 MiB
Input example #1
4
1 2
2 3
2 4
6
I 1 1
G 1 1
G 3 4
I 2 3
G 1 1
G 3 4
Output example #1
1
0
1
3