Pagini recente » Cod sursa (job #481750) | Cod sursa (job #2899170) | Cod sursa (job #1715048) | Cod sursa (job #1002974) | Cod sursa (job #2414552)
#include <bits/stdc++.h>
using namespace std;ifstream in("asmax.in");ofstream out("asmax.out");
#define NMAX 16001
vector <int>g[NMAX];int v[NMAX],d[NMAX],n;bool vizitat[NMAX];void dfs(int node){vizitat[node]=1;for(auto y:g[node])if(!vizitat[y]){dfs(y);d[node]=d[node]+max(d[y],0);}}int main(){in>>n;for(int i=1;i<=n;i++)in>>d[i];int x,y;while(in>>x>>y){g[x].push_back(y);g[y].push_back(x);}int maxim=-100000000;dfs(1);for(int i=1;i<=n;i++)maxim=max(d[i],maxim);out<<maxim;return 0;}