Cod sursa(job #1060074)

Utilizator alex.glontGlontaru Alexandru alex.glont Data 17 decembrie 2013 16:11:27
Problema Asmax Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include<fstream>
#include<vector>

#define INF -10000000

using namespace std;

fstream in ( "asmax.in" , ios::in ),
        out( "asmax.out", ios::out);

vector <int> copii[16001];
int n, v[16001], y, a, b, m = INF ;
bool viz[16001];


void dfs( int );

int main(){

    in >> n;

    for( int i=1; i<=n; i++){

        in >> v[i];
    }

    for( int i=1; i<n; i++){

        in >> a >> b;
        copii[a].push_back( b );
        copii[b].push_back( a );
    }

    dfs( 1 );

    out << m-200 <<'\n';
    return 0;

}

void dfs( int x ){

    viz[x] = true;

    for( int i=0; i<copii[x].size(); i++){

        y = copii[x][i];

        if( !viz[y] ){
            dfs(y);
            if( v[y]>0)
                v[x] += v[y];
        }
    }

    if( m < v[x] ){

        m = v[x];
    }

    //out << x << " -> " << v[x] << "\n";

}