Path queries - MarisaOJ: Marisa Online Judge

Path queries

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree of $n$ vertices, vertex $i$ has value $A_i$. Given $q$ queries of either form: - `1 u x` : change the value on vertex $u$ to $x$. - `2 u v` : find the maximum value on the simple path from $u$ to $v$. Answer queries of type $2$! ### Input - The first line contains two integers $n, q$. - The second line contains $n$ integers $A_i$. - The next $n$ lines, each line contains two integers $u, v$, there is an edge between $u$ and $v$. - The next $q$ lines, each line contains three integers, a query. ### Output - Print the answer for each query of type $2$. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i, x \le 10^9$. - $1 \le u, v \le n$. ### Example Input: ``` 5 6 3 5 3 7 4 1 2 1 3 2 4 1 5 2 2 2 1 1 9 2 5 2 2 2 5 1 2 10 1 1 9 ``` Output: ``` 5 9 9 ```