Cod sursa(job #2211747)

Utilizator 12222Fendt 1000 Vario 12222 Data 11 iunie 2018 17:34:22
Problema Asmax Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("asmax.in");
ofstream fout("asmax.out");

int n;
int dp[16005],sol;
bitset<16005>viz;
vector<int>L[16005];

void Citire()
{
    fin>>n;
    for(int i=1;i<=n;i++)
        fin>>dp[i];

    for(int i=1;i<n;i++)
    {
        int x,y;
        fin>>x>>y;
        L[x].push_back(y);
        L[y].push_back(x);
    }

}

void DFS(int nod,int tata)
{
    viz[nod]=1;
    for(auto i:L[nod])
        if(i!=tata)
        {
            if(!viz[i])DFS(i,nod);

            if(dp[i]>0)dp[nod]+=dp[i];
        }

    sol=max(sol,dp[nod]);
}

int main()
{
    Citire();
    sol=-1005;
    DFS(1,0);
    fout<<sol;
    return 0;
}