#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
int N;
vector<int> stars(MAXN); // Stars of each city
vector<vector<int>> adj(MAXN); // Adjacency list for the tree
vector<int> dp(MAXN, 1); // DP array to store the LIS ending at each city
vector<bool> visited(MAXN, false); // Visited array for DFS
// Depth-First Search to compute the longest increasing path
void dfs(int node, int parent) {
visited[node] = true;
for (int neighbor : adj[node]) {
if (neighbor == parent) continue; // Skip the parent to avoid revisiting
if (!visited[neighbor]) {
dfs(neighbor, node); // Recursively explore neighbors
// Update the dp array if we can eat at the neighbor
if (stars[neighbor] > stars[node]) {
dp[neighbor] = max(dp[neighbor], dp[node] + 1);
} else if (stars[neighbor] < stars[node]) {
dp[node] = max(dp[node], dp[neighbor] + 1);
}
}
}
}
int main() {
cin >> N;
// Input the stars of each city
for (int i = 1; i <= N; i++) {
cin >> stars[i];
}
// Input the roads (edges)
for (int i = 1; i < N; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
// Start DFS from any node, here we start from city 1
dfs(1, -1);
// The result is the maximum value in the dp array
int max_restaurants = *max_element(dp.begin() + 1, dp.begin() + N + 1);
// Output the result
cout << max_restaurants << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhOID0gMTAwMDA1OwoKaW50IE47CnZlY3RvcjxpbnQ+IHN0YXJzKE1BWE4pOyAgICAgICAgICAgIC8vIFN0YXJzIG9mIGVhY2ggY2l0eQp2ZWN0b3I8dmVjdG9yPGludD4+IGFkaihNQVhOKTsgICAgICAgLy8gQWRqYWNlbmN5IGxpc3QgZm9yIHRoZSB0cmVlCnZlY3RvcjxpbnQ+IGRwKE1BWE4sIDEpOyAgICAgICAgICAgICAvLyBEUCBhcnJheSB0byBzdG9yZSB0aGUgTElTIGVuZ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IGZvciAoaW50IGkgPSAxOyBpIDw9IE47IGkrKykgewogICAgICAgIGNpbiA+PiBzdGFyc1tpXTsKICAgIH0KICAgIAogICAgLy8gSW5wdXQgdGhlIHJvYWRzIChlZGdlcykKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgTjsgaSsrKSB7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgY2luID4+IHUgPj4gdjsKICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGFkalt2XS5wdXNoX2JhY2sodSk7CiAgICB9CiAgICAKICAgIC8vIFN0YXJ0IERGUyBmcm9tIGFueSBub2RlLCBoZXJlIHdlIHN0YXJ0IGZyb20gY2l0eSAxCiAgICBkZnMoMSwgLTEpOwogICAgCiAgICAvLyBUaGUgcmVzdWx0IGlzIHRoZSBtYXhpbXVtIHZhbHVlIGluIHRoZSBkcCBhcnJheQogICAgaW50IG1heF9yZXN0YXVyYW50cyA9ICptYXhfZWxlbWVudChkcC5iZWdpbigpICsgMSwgZHAuYmVnaW4oKSArIE4gKyAxKTsKICAgIAogICAgLy8gT3V0cHV0IHRoZSByZXN1bHQKICAgIGNvdXQgPDwgbWF4X3Jlc3RhdXJhbnRzIDw8IGVuZGw7CiAgICAKICAgIHJldHVybiAwOwp9Cg==