#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector S(N); for(auto &s : S) cin >> s; vector> V(N); for(int i=0; i> Graph(N); for(int i=0; i> u >> v; u--; v--; Graph.at(u).push_back(v); Graph.at(v).push_back(u); } vector dp(N); for(auto [s,pos] : V){ dp.at(pos) += s; for(auto to : Graph.at(pos)) if(S.at(pos) < S.at(to)) dp.at(to) = max(dp.at(to),dp.at(pos)); } cout << *max_element(dp.begin(),dp.end()) << endl; }