Maximum edge cost on a tree path
Time limit2sMemory limit512 MB
- Level
Not classified yet
- Solved
- No attempts yet
Problem
You are given a tree with vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered 1 to , the edges are numbered 1 to , and every edge has one cost.
Write a program that handles the following two queries.
1 i c: change the cost of edge to .2 u v: print the largest cost among the edges on the simple path from to .
In a tree there is exactly one simple path between two different vertices.
Input
The first line contains the number of vertices ().
Each of the next lines describes one edge. The -th of those lines contains the two vertex numbers and joined by edge and the cost of that edge ().
The next line contains the number of queries ().
Each of the next lines contains one query. A query of type 1 satisfies and . A query of type 2 satisfies , and differs from .
Output
For each query of type 2, print the answer on its own line, in the order the queries are given.