Pagini recente » Cod sursa (job #2986618) | Cod sursa (job #2893969) | Cod sursa (job #3286584) | Monitorul de evaluare | Cod sursa (job #3281029)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("asmax.in");
ofstream fout("asmax.out");
/**
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
*/
int n, v[16003], cnt, sum, maxx, summax, a[16003];
vector <int> g[16003];
bitset <16003> viz;
void DFS(int x)
{
viz[x] = 1;
for (int i : g[x])
if (viz[i] == 0)
{
a[i] = v[i];
DFS(i);
if (a[x] + a[i] > a[x]) a[x] += a[i];
}
}
int main()
{
ios_base::sync_with_stdio(0);
fin.tie(0);
fout.tie(0);
int i, j, x, y;
fin >> n;
for (i = 1; i <= n; i++)
fin >> v[i];
for (i = 1; i < n; i++)
{
fin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
maxx = INT_MIN;
a[1] = v[1];
DFS(1);
for (i = 1; i <= n; i++)
maxx = max(maxx, a[i]);
fout << maxx << "\n";
return 0;
}