Grapevine

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

Syrup the Turtle waters the huge Grapevine which snakes around town. The layout of the Grapevine can be best described as having NN leafy joints, which Syrup has numbered 11 to NN, connected by N1N - 1 branches also numbered 11 to N1N - 1. Each branch ii directly connects two joints A_iA\_i and B_iB\_i, and has a length of W_iW\_i. No two branches directly connect the same pair of joints, and as part of the single Grapevine, every joint is connected to every other either directly or indirectly by branches.

With his sturdy hose and a little handiwork, Syrup is able to sway the growth of the Grapevine as he deems fit. In particular, he can soak a joint of the vine - causing it to immediately sprout a single giant grape if it was empty, or instead dislodging the grape there if one was present.

He can also anneal a branch with water, extending or shortening it to a new length w_iw\_i by spraying at the right pressure and angle. To make sure things are on track, Syrup will periodically stand atop an elevated joint and seek for the closest grape. The distance from such a joint to a grape is defined by the shortest path starting from said joint, traversing a number of branches (or none at all), and ending at the grape’s own joint.

Right now, the Grapevine has no grapes attached after the last passing storm. Syrup has his watering agenda of QQ actions planned out for the week and is about to begin spraying; but first, he needs to know what distances to expect when he seeks for grapes along the way. Given Syrup’s watering plans, your task is to find for each planned seek the distance from the specified joint to the nearest grape.

입력

Your program must read from standard input.

The first line contains two integers, NN and QQ.

N1N - 1 lines will follow. The iith line contains three integers, A_iA\_i, B_iB\_i, and W_iW\_i, describing a single branch.

QQ lines will follow, each representing an action by Syrup.

  • If the first integer of the line is 11, it represents a seek and 11 integer q_iq\_i will follow. This means that you are to determine the distance between joint q_iq\_i and the nearest joint with a grape, and output this distance. If there are no grapes on the Grapevine, output 1-1 instead.
  • If the first integer of the line is 22, it represents a soak and 11 integer u_iu\_i will follow. This means that joint u_iu\_i is soaked and grows a grape or has its grape dislodged.
  • If the first integer of the line is 33, it represents an anneal and 33 integers a_ia\_i, b_ib\_i, and w_iw\_i will follow. This means that the length of the branch between joints a_ia\_i and b_ib\_i has had its length changed to w_iw\_i. It is guaranteed that a branch between joints a_ia\_i and b_ib\_i exists.

출력

Your program must print to standard output.

For each seek action, output one line with a single integer, the distance to the closest grape, or 1-1 if no grapes are present.

제한

  • 2N100,0002 ≤ N ≤ 100\\,000
  • 1Q100,0001 ≤ Q ≤ 100\\,000
  • 1A_iB_iN1 ≤ A\_i \ne B\_i ≤ N
  • 0W_i1090 ≤ W\_i ≤ 10^9