QTREE  Query on a tree
You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N1.
We will ask you to perfrom some instructions of the following form:
 CHANGE i ti : change the cost of the ith edge to ti
or  QUERY a b : ask for the maximum edge cost on the path from node a to node b
Input
The first line of input contains an integer t, the number of test cases (t <= 20). t test cases follow.
For each test case:
 In the first line there is an integer N (N <= 10000),
 In the next N1 lines, the ith line describes the ith edge: a line with three integers a b c denotes an edge between a, b of cost c (c <= 1000000),
 The next lines contain instructions "CHANGE i ti" or "QUERY a b",
 The end of each test case is signified by the string "DONE".
There is one blank line between successive tests.
Output
For each "QUERY" operation, write one integer representing its result.
Example
Input: 1 3 1 2 1 2 3 2 QUERY 1 2 CHANGE 1 3 QUERY 1 2 DONE Output: 1 3
hide comments
‡■■Lãng du■■‡:
20141030 17:04:44
My solution, complexity O(logn ^2) for each "query" and O(logn) for each "Change"??? Is the time limit so low ?? Last edit: 20141030 22:54:43 

r64:
20140806 04:11:59
How many queries are there at most? 

zicowa:
20140708 16:37:09
:D 

devu:
20131201 20:27:49
Finally Accepted! Values are nonneg always, no tricky test data but definitely difficult to debug. Last edit: 20131201 20:28:19 

Mojtaba FayazBakhsh:
20130822 18:59:00
lots of ambiguous things


Abhay Goel:
20130103 16:06:58
Do all numbers have to be >=0? Can edges have negative weights? 
Added by:  ThanhVy Hua 
Date:  20050608 
Time limit:  1s 
Source limit:  15000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  ADA95 ASM32 BASH BF C CSHARP CPP CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PASGPC PASFPC PERL PHP PIKE PRLGswi PYTHON RUBY SCM qobi SCM guile ST TEXT WHITESPACE 