Mai intai trebuie sa te autentifici.
Cod sursa(job #2704879)
Utilizator | Data | 11 februarie 2021 15:44:53 | |
---|---|---|---|
Problema | Asmax | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <fstream>
#include <vector>
using namespace std;
const int N=16001;
bool viz[N];
int n,d[N],sum=-1001,sol[N];
vector <int> a[N];
ifstream in("asmax.in");
ofstream out("asmax.out");
void dfs(int x)
{
viz[x]=true;
sol[x]=d[x];
for(auto y:a[x])
{
if(!viz[y])
{
dfs(y);
if(sol[y] > 0)
{
sol[x] += sol[y];
}
}
sum=max(sum,sol[x]);
}
}
int main()
{
in >> n;
int x,y;
for(int i=1; i <= n; i++)
{
in >> d[i];
}
while(in >> x >> y)
{
a[x].push_back(y);
a[y].push_back(x);
}
dfs(1);
out << sum;
return 0;
}