Pagini recente » Cod sursa (job #1802273) | Cod sursa (job #142872) | Cod sursa (job #2439138) | Cod sursa (job #1757830) | Cod sursa (job #1835845)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("asmax.in");
ofstream fout ("asmax.out");
struct qq
{
int n;
vector<int> i;
};
vector<qq> g;
int n, smax = -0x3f3f3f3f, maxi = -0x3f3f3f3f;
bool v[16001];
int dfs(int na)
{
v[na] = true;
for (int x : g[na].i)
if (v[x] == false)
g[na].n += dfs(x);
if (g[na].n > 0) return g[na].n;
return 0;
}
int main()
{
fin >> n;
g = vector<qq>(n + 1);
for (int i = 1; i <= n; ++ i)
{
fin >> g[i].n;
maxi = max(maxi, g[i].n);
}
int x, y;
while(fin >> x >> y)
{
g[x].i.push_back(y);
g[y].i.push_back(x);
}
for (int i = 1; i <= n; ++ i)
if (g[i].n > 0)
smax = max(smax, dfs(i));
fout << max(smax, maxi);
return 0;
}