You are given a tree of n nodes and n-1 undirected edges . You are also given an array values ,
where values[i] represent the value on i node . You have to nd the length of the longest strictly
increasing path in the tree.(1-based indexing is used)
Example 1:
Input:
n = 3
edges = {{1,2}, {1,3}}
values = {4, 3, 5}
Output:
3
Explanation:
as we can see in the tree , the longest strictly increasing path is 2 -> 1 -> 3 as
their values(3, 4, 5) are in strictly increasing order;
----
我直接dfs做,结果超时了,因为是对每个点都进行dfs,然后也没有保存结果,所以就超时了,参考别的ac的代码,就是新建一个数组,dp,保存每个点数据,然后取最大值即可。
python的话,直接加个cache就行。
学到了这个dp,以后得试试。