Pagini recente » Cod sursa (job #634678) | Cod sursa (job #491560) | Cod sursa (job #1498710) | Cod sursa (job #957392) | Cod sursa (job #1510932)
#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];
}