This page is still under construction.

Parts of this page are still being built. What you see may change.

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 NN vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered 1 to NN, the edges are numbered 1 to N−1N-1, and every edge has one cost.

Write a program that handles the following two queries.

  • 1 i c: change the cost of edge ii to cc.
  • 2 u v: print the largest cost among the edges on the simple path from uu to vv.

In a tree there is exactly one simple path between two different vertices.

Input

The first line contains the number of vertices NN (2≤N≤100 0002 \le N \le 100\,000).

Each of the next N−1N-1 lines describes one edge. The ii-th of those lines contains the two vertex numbers uu and vv joined by edge ii and the cost ww of that edge (1≤w≤1 000 0001 \le w \le 1\,000\,000).

The next line contains the number of queries MM (1≤M≤100 0001 \le M \le 100\,000).

Each of the next MM lines contains one query. A query of type 1 satisfies 1≤i≤N−11 \le i \le N-1 and 1≤c≤1 000 0001 \le c \le 1\,000\,000. A query of type 2 satisfies 1≤u,v≤N1 \le u, v \le N, and uu differs from vv.

Output

For each query of type 2, print the answer on its own line, in the order the queries are given.

Examples2

  1. Example 1

    Input
    3
    1 2 1
    2 3 2
    3
    2 1 2
    1 1 3
    2 1 2
    
    Expected output
    1
    3
    
  2. Example 2

    Input
    5
    2 1 5
    2 3 2
    4 3 7
    4 5 1
    6
    2 1 5
    2 2 3
    1 3 1
    2 1 5
    1 1 9
    2 5 1
    
    Expected output
    7
    2
    5
    9