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
mb81:
20180730 08:45:48
BK 

spojmaster_9:
20180726 15:14:33
Finally, I did it, after 17 times 

pshishod2645:
20180724 16:41:37
Time limit is too strict.


dynamite_iit:
20180420 16:48:59
https://ideone.com/nYZ4ru


lukamercep:
20180401 14:52:54
Don't use c++ MIN and MAX functions from algorithm, they are very slow, us IF instead! 

siva2697:
20180223 17:59:22
Very Nice Problem Learnt New Concept C++ working LCA with DP too Last edit: 20180223 18:52:18 

sagar2009kumsr:
20171228 07:32:37
Is c++ solution is submitting on this ?? 

ganeshjadhav:
20171225 19:11:29
Credit goes to Anudeep such a nice blog HLD+segment tree. 

labo:
20170906 20:51:43
Did anyone solve this in Python ? Get TLE with HLDâ€¦ 

coderbond007:
20170710 17:24:42
Java got TLE. Same code in C++ passed. :( 
Added by:  ThanhVy Hua 
Date:  20050608 
Time limit:  0.851s 
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 