This page is still under construction.

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

The Flower of the Game

Time limit6sMemory limit1024 MB

Summary
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 NN vertices (a connected graph with no undirected cycles) is given. The vertices are numbered from 11 to NN, and the edges are numbered from 11 to N−1N-1. Vertex ii has an integer weight AiA_i.

For a vertex sequence v1,v2,⋯ ,vkv_1, v_2, \cdots, v_k, if there is an edge between viv_i and vi+1v_{i+1} and Avi<Avi+1A_{v_i} < A_{v_{i+1}} (1≤i≤k−1)(1 \le i \le k-1), then v1,v2,⋯ ,vkv_1, v_2, \cdots, v_k is an increasing path of length kk.

Find the length of the longest increasing path in the given tree, then process the following query.

  • ii xx: Change the weight AiA_i of vertex ii to xx, then output the length of the longest increasing path in the tree.

Input

The first line contains the size of the tree NN and the number of queries MM.

The second line contains the weights AiA_i of each vertex, separated by spaces.

The next N−1N-1 lines each contain two vertex numbers uu and vv connected by an edge.

The next MM lines each contain the query information ii and xx.

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 MM queries on its own line, in order.

Constraints

  • 1≤N,M≤100,0001 \leq N, M \leq 100,000
  • 1≤Ai≤1091 \leq A_i \leq 10^{9}
  • 1≤u,v≤N1 \leq u, v \leq N
  • 1≤i≤N1 \leq i \leq N
  • 1≤x≤1091 \leq x \leq 10^{9}

Examples1

  1. Example 1

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