Beautiful path
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given a connected graph with n nodes indexed from 1 to n and n-1 undirected edges. The nodes with index i has a value a_i. We call a path beautiful if and only if all nodes in it are distinct and the values of the nodes are strictly rise from one end to the other.

Find the length of the longest beautiful path, and print it out.

输入描述:

The first line contains a positive integer , indicates the number of the vertices.

Each of the next lines contains two integers , representing an edge between ui and vi.

The next line contains n integers — the array a.

输出描述:

The only line contains ONE integer indicates the length of the longest beautiful path.
示例1

输入

复制
2
1 2
1 2

输出

复制
2
示例2

输入

复制
4
1 2
1 3
1 4
2 1 3 4

输出

复制
3