Cod sursa(job #800697)

Utilizator TheShadowsAlexandru Cristian TheShadows Data 22 octombrie 2012 12:55:01
Problema Asmax Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include<fstream>
#include<vector>
using namespace std;
const int LIM = 16010; const bool debug = false;
int val[LIM], maxim;
vector <int> rel[LIM];
int getValues(int pos, int parent){
    int sum=val[pos], c;
    for(int i=0; i < rel[pos].size(); ++i)
        if(rel[pos][i]!=parent){
            c = getValues(rel[pos][i], pos);
            if(c>0) sum+=c;
        }
    if(sum>maxim) maxim=sum;
    return sum;
}
int main(){
    ifstream in("asmax.in"); ofstream out("asmax.out");
    int n; in>>n;
    for(int i=1; i <= n; ++i)
        in>>val[i];
    int a,b;
    for(int i=1; i <= n-1; ++i){
        in>>a>>b; rel[a].push_back(b); rel[b].push_back(a);
    }
    int c;
    getValues(1, 0);
    out<<maxim<<"\n";
    return 0;
}