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
fanatique:
20161124 19:43:49
HLD + segment tree... spent lot of time on debugging :( 

brainf_ck:
20160919 00:10:23
Nice problem for HLD, thanks AnuDeep! Last edit: 20160919 06:04:18 

andrewchen:
20160730 10:30:40
Why isn't c++11 supported on this problem? Last edit: 20160730 10:30:51 

Tuukka Korhonen:
20160715 15:26:01
Why I cant use c++11? 

Sliti khaled:
20160513 03:04:20
Very good problem ! 

haogram:
20160422 15:43:37
treechain seperate 

Vipul:
20160415 16:46:37
Anudeep Rocks.... 

linkret:
20160322 16:17:44
HLD is Heavy  Light Decomposition. Alot of code. 

austine:
20160303 10:34:01
Classical problem 

Obliterator:
20151105 06:45:11
Huge number of accepted solutions is because of Anudeep's blog explaining HLD very clearly http://blog.anudeep2011.com/heavylightdecomposition/ Last edit: 20151106 12:07:05 
Added by:  ThanhVy Hua 
Date:  20050608 
Time limit:  0.851s 
Source limit:  15000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  ADA ASM BASH BF C C# C++ 5 CLPS LISP sbcl LISP clisp D FORT HASK ICON ICK JAVA LUA NEM NICE CAML PAS gpc PAS fpc PERL PHP PIKE PRLG PYTH 2.7 RUBY SCM qobi SCM guile ST TEXT WSPC 