Pagini recente » Cod sursa (job #2232630) | Cod sursa (job #1450784) | Cod sursa (job #28817) | Cod sursa (job #443473) | Cod sursa (job #2603693)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <vector>
#include <cstring>
std::ifstream f("easygraph.in");
std::ofstream g("easygraph.out");
std::vector <int> v[16001];
bool viz[16001];
int n, m, t, i, x, y;
long long a[16001], smax = -16000000001;
void dfs(int nod)
{
viz[nod] = 1;
for(std::vector<int>::iterator it=v[nod].begin(); it!=v[nod].end(); ++it)
if(viz[*it]==0)
{
a[*it]+=a[nod];
dfs(*it);
}
}
int main()
{
f>>n>>m;
for(i=1; i<=n; ++i)
{
f>>a[i];
}
for(i=1; i<n; ++i)
{
f>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1);
for(i=1; i<=n; ++i)
if(a[i]>smax)
smax=a[i];
g<<smax<<"\n";
return 0;
}