Cod sursa(job #1510932)

Utilizator cristian.caldareaCaldarea Cristian Daniel cristian.caldarea Data 25 octombrie 2015 19:53:37
Problema Asmax Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

using VI = vector<int>;
const int Inf = 0x3f3f3f3f;

int n, smax = -Inf;
vector<VI> G;
VI v, s, r;
vector<bool> b;

void Read();
void Dfs(int x);


int main()
{
    Read();
    Dfs(1);
    fout << smax;
    fin.close();
    fout.close();
    return 0;
}

void Read()
{
    fin >> n;
    G = vector<VI>(n + 1);
    s = VI(n + 1);
    v = VI(n + 1);
    r = VI(n + 1);
    b = vector<bool>(n + 1);
    int x, y;
    for ( int i = 1; i <= n; i++)
        fin >> s[i];
    while( fin >> x >> y )
    {
        G[x].push_back(y);
        G[y].push_back(x);
    }
}

void Dfs(int x )
{

    int y = 0;
    b[x] = 1;

    for (const int& y : G[x])
        if ( !b[y] )
        {
           Dfs(y);
           if ( s[y] > 0 )
            s[x] += s[y];
        }
    if ( s[x] > smax )
        smax = s[x];
}