#SGM0000082. Truy vấn trên cây (Query on a tree)
Truy vấn trên cây (Query on a tree)
Query on a tree
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem
You are given an edge-weighted tree. Support changing the weight of one edge and querying the maximum edge weight on the path between two vertices. This PHOJ version contains exactly one tree per input; the command sequence ends with DONE.
Input
The first line contains . The next lines contain u v w; the -th such line describes edge . Then follow commands:
CHANGE i x: set the weight of edge to .QUERY a b: query the maximum edge weight on the path from to .DONE: end the command sequence.
Output
For each QUERY, print the maximum edge weight on the requested path. If , the path contains no edge and the answer is 0.
Subtasks
Subtask 1 (20%)
- The tree size and number of operations are at most 20.
- All other conditions are the same as Subtask 3.
Subtask 2 (30%)
- The tree size and number of operations are at most 2000.
- All other conditions are the same as Subtask 3.
Subtask 3 (50%)
- .
- Edge weights are at most .
- The PHOJ version uses one test case.
Example
Input
1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
QUERY 1 1
DONE
Output
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Explanation
The tree has one vertex and no edge, so every path from vertex 1 to itself has maximum edge weight 0.