Submit | All submissions | Best solutions | Back to list |
QTREE - Query on a tree |
You are given a tree (an acyclic undirected connected graph) with N nodes, and edges numbered 1, 2, 3...N-1.
We will ask you to perfrom some instructions of the following form:
- CHANGE i ti : change the cost of the i-th 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 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 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
Added by: | Thanh-Vy Hua |
Date: | 2005-06-08 |
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 PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST TEXT WHITESPACE |
hide comments
|
||||||||||||
2017-07-05 14:08:07 Harish Chandra Thuwal
Hi can anyone explain how the LCA is implemented in anudeep's (HLD code)blog ? |
||||||||||||
2017-06-27 15:50:09
HLD + segment tree . do read HLD from anudeep's blog. |
||||||||||||
2017-06-27 09:23:10
my code is getting complied in codeblocks but when i submit it here its showing compilation error.......??? I use c++ Last edit: 2017-06-27 09:23:32 |
||||||||||||
2017-01-12 08:47:08 67890
Did you talk something about my username?⊙▂⊙ @hld67890 |
||||||||||||
2016-11-24 19:43:49 fanatique
HLD + segment tree... spent lot of time on debugging :( |
||||||||||||
2016-09-19 00:10:23
Nice problem for HLD, thanks AnuDeep! Last edit: 2016-09-19 06:04:18 |
||||||||||||
2016-07-30 10:30:40
Why isn't c++11 supported on this problem? Last edit: 2016-07-30 10:30:51 |
||||||||||||
2016-07-15 15:26:01 Tuukka Korhonen
Why I cant use c++11? |
||||||||||||
2016-05-13 03:04:20 Sliti khaled
Very good problem ! |
||||||||||||
2016-04-22 15:43:37
tree-chain seperate |