Pagini recente » Istoria paginii runda/cel_mai_mare_olimpicar_2019_oni2009_zi1/clasament | Cod sursa (job #397321) | Istoria paginii utilizator/florinela | Cod sursa (job #675321) | Cod sursa (job #1708331)
#include <bits/stdc++.h>
using namespace std;
int cst[100010],b,m,n,a,i,x,y,ma=INT_MIN,sum[100010];
vector<int>g[100010];
bool sel[100010];
void DFS(int x)
{
int i;
sel[x]=true;
int S=0;
for(i=0; i<g[x].size(); ++i)
{
if(!sel[g[x][i]])DFS(g[x][i]);
if(sum[g[x][i]]>0)S+=sum[g[x][i]];
}
sum[x]=cst[x]+S;
ma=max(ma,sum[x]);
}
int main()
{
ifstream f ("asmax.in");
freopen("asmax.out","w",stdout);
f>>n;
for(i=1; i<=n; ++i)
f>>cst[i];
while(f>>x>>y)
{
g[x].push_back(y);
g[y].push_back(x);
}
DFS(1);
printf("%d\n",ma);
return 0;
}