Under construction

Still being built. Things may change

Tree and Easy Queries

Time limit2.5sMemory limit1024 MB

Summary
Given a weighted tree whose edge lengths change, report the longest simple path through a queried vertex after each update.
Level

Hard8 of 10

Topics
Tree, Segment tree, Divide and conquer
Solved
No attempts yet

Problem

Bru was shocked by how hard the other problems were, so he decided to write a problem that participants with low skill, like himself, could enjoy.

A tree is given. Process the following two kinds of queries.

  • 1 k x: Change the length of edge kk to xx.
  • 2 p: Print the length of the longest simple path that passes through vertex pp.

A simple path is a path that does not pass through any vertex more than once.

Vertices are numbered starting from 1.

Input

The first line contains the number of vertices NN and the number of queries QQ. (2≤N,Q≤150,0002 \le N, Q \le 150{,}000)

From the second line through line NN, the next N−1N-1 lines give the edges from edge 1 to edge N−1N-1, in order. For each edge, the two vertices it connects, uiu_i and viv_i, and the edge length did_i are given in that order. (1≤ui,vi≤N1 \le u_i, v_i \le N, ui≠viu_i \ne v_i, 1≤di≤1091 \le d_i \le 10^9)

From line N+1N+1 through line N+QN+Q, the queries are given. Each query is one of the two kinds described above. (1≤k<N1 \le k < N, 1≤x≤1091 \le x \le 10^9, 1≤p≤N1 \le p \le N)

The given tree is guaranteed to be a valid tree. Also, at least one query of type 2 is guaranteed.

Output

For each query of type 2, print the answer on its own line.

Examples1

  1. Example 1

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