SP2666 QTREE4 - Query on a tree IV

Description

You are given a tree (an acyclic undirected connected graph) with $N$ nodes, and nodes numbered $1,2,3\ldots,N$. Each edge has an integer value assigned to it (note that the value can be negative). Each node has a color, white or black. We define $dist(a, b)$ as the sum of the value of the edges on the path from node $a$ to node $b$. All the nodes are white initially. We will ask you to perfrom some instructions of the following form: - `C a` : change the color of node $a$.(from black to white or from white to black) - `A` : ask for the maximum $dist(a, b)$, both of node a and node $b$ must be white ($a$ can be equal to $b$). Obviously, as long as there is a white node, the result will alway be non negative.

Input Format

- In the first line there is an integer $N$. ($N \leq 100000$) - In the next $N-1$ lines, the $i$-th line describes the $i$-th edge: a line with three integers $a,b,c$ denotes an edge between $a, b$ of value $c$. ($-10^3 \leq c \leq 10^3$) - In the next line, there is an integer $Q$ denotes the number of instructions. ($Q \leq 100000$) - In the next $Q$ lines, each line contains an instruction `C a` or `A`.

Output Format

For each `A` operation, write one integer representing its result. If there is no white node in the tree, you should write `They have disappeared.`.