Tree and Easy Queries
Time limit2.5sMemory limit1024 MB
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 to .2 p: Print the length of the longest simple path that passes through vertex .
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 and the number of queries . ()
From the second line through line , the next lines give the edges from edge 1 to edge , in order. For each edge, the two vertices it connects, and , and the edge length are given in that order. (, , )
From line through line , the queries are given. Each query is one of the two kinds described above. (, , )
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.