Pagini recente » Monitorul de evaluare | Cod sursa (job #3159056) | Cod sursa (job #1121008) | Cod sursa (job #771837) | Cod sursa (job #1759897)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("asmax.in");
ofstream fout("asmax.out");
const int nmax = 16005;
int N,dp[nmax],ans;
bool viz[nmax];
vector < int > L[nmax];
inline void Read()
{
int i,x,y;
fin >> N;
for(i = 1; i <= N; i++) fin >> dp[i];
for(i = 1; i < N; i++)
{
fin >> x >> y;
L[x].push_back(y);
L[y].push_back(x);
}
}
inline void DFS(int nod, int tata)
{
viz[nod] = true;
for(auto it : L[nod])
{
if(it != tata)
{
if(!viz[it]) DFS(it,nod);
if(dp[it] > 0) dp[nod] += dp[it];
}
}
ans = max(ans,dp[nod]);
}
int main()
{
Read();
DFS(1,0);
fout << ans << "\n";
fout.close();
return 0;
}