Cod sursa(job #2603693)

Utilizator bmc213Mihai Cosmin bmc213 Data 20 aprilie 2020 17:51:48
Problema Asmax Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <climits>
#include <vector>
#include <cstring>

std::ifstream f("easygraph.in");
std::ofstream g("easygraph.out");

std::vector <int> v[16001];
bool viz[16001];
int n, m, t, i, x, y;
long long a[16001], smax = -16000000001;

void dfs(int nod)
{
    viz[nod] = 1;
    for(std::vector<int>::iterator it=v[nod].begin(); it!=v[nod].end(); ++it)
        if(viz[*it]==0)
        {
            a[*it]+=a[nod];
            dfs(*it);
        }
}
int main()
{
    f>>n>>m;
    for(i=1; i<=n; ++i)
    {
        f>>a[i];
    }
    for(i=1; i<n; ++i)
    {
        f>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1);
    for(i=1; i<=n; ++i)
        if(a[i]>smax)
            smax=a[i];
    g<<smax<<"\n";

    return 0;
}