#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
int max_restaurants = 0; // Store the maximum number of restaurants visited
// Depth-First Search to compute the longest increasing path
void dfs(int node, int parent, int length) {
// Update the global max_restaurants count
max_restaurants = max(max_restaurants, length);
// Explore all neighbors
for (int neighbor : adj[node]) {
if (neighbor == parent) continue; // Skip the parent to avoid revisiting
// If the neighbor's stars are greater, we can eat there
if (stars[neighbor] > stars[node]) {
dfs(neighbor, node, length + 1);
} else {
// If not, we just move on without incrementing the dining count
dfs(neighbor, node, 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 every city to ensure we check all possible starting points
for (int i = 1; i <= N; i++) {
dfs(i, -1, 1); // Start DFS from city i, no parent (-1), starting length is 1
}
// Output the result
cout << max_restaurants << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBNQVhOID0gMTAwMDA1OwoKaW50IE47CnZlY3RvcjxpbnQ+IHN0YXJzKE1BWE4pOyAgICAgICAgICAgIC8vIFN0YXJzIG9mIGVhY2ggY2l0eQp2ZWN0b3I8dmVjdG9yPGludD4+IGFkaihNQVhOKTsgICAgICAgLy8gQWRqYWNlbmN5IGxpc3QgZm9yIHRoZSB0cmVlCmludCBtYXhfcmVzdGF1cmFudHMgPSAwOyAgICAgICAgICAgICAvLyBTdG9yZSB0aGUgbWF4aW11bSBudW1iZXIgb2YgcmVzdGF1cmFudHMgdmlzaXRlZAoKLy8gRGVwdGgtRmlyc3QgU2VhcmNoIHRvI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ykgewogICAgICAgIGludCB1LCB2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh2KTsKICAgICAgICBhZGpbdl0ucHVzaF9iYWNrKHUpOwogICAgfQogICAgCiAgICAvLyBTdGFydCBERlMgZnJvbSBldmVyeSBjaXR5IHRvIGVuc3VyZSB3ZSBjaGVjayBhbGwgcG9zc2libGUgc3RhcnRpbmcgcG9pbnRzCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBOOyBpKyspIHsKICAgICAgICBkZnMoaSwgLTEsIDEpOyAgLy8gU3RhcnQgREZTIGZyb20gY2l0eSBpLCBubyBwYXJlbnQgKC0xKSwgc3RhcnRpbmcgbGVuZ3RoIGlzIDEKICAgIH0KICAgIAogICAgLy8gT3V0cHV0IHRoZSByZXN1bHQKICAgIGNvdXQgPDwgbWF4X3Jlc3RhdXJhbnRzIDw8IGVuZGw7CiAgICAKICAgIHJldHVybiAwOwp9Cg==