The Flower of the Game
Time limit6sMemory limit1024 MB
Given a weighted tree, find the longest path whose vertex weights strictly increase, and report that length again after each weight update query.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Segment tree
- Solved
- No attempts yet
Problem
Do you know syllogism? blackking knows it well.
PS is a game. Trees and queries are the flowers of PS. Therefore, trees and queries are the flowers of the game.
- blackking26
A tree with vertices (a connected graph with no undirected cycles) is given. The vertices are numbered from to , and the edges are numbered from to . Vertex has an integer weight .
For a vertex sequence , if there is an edge between and and , then is an increasing path of length .
Find the length of the longest increasing path in the given tree, then process the following query.
- : Change the weight of vertex to , then output the length of the longest increasing path in the tree.
Input
The first line contains the size of the tree and the number of queries .
The second line contains the weights of each vertex, separated by spaces.
The next lines each contain two vertex numbers and connected by an edge.
The next lines each contain the query information and .
Output
On the first line, print the length of the longest increasing path in the given tree.
Then print the result of each of the queries on its own line, in order.