Pagini recente » Cod sursa (job #1424064) | Rating Andra Smarandache (AndraSmarandache) | Cod sursa (job #1473846) | Cod sursa (job #1209097) | Cod sursa (job #3030629)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("asmax.in");
ofstream cout("asmax.out");
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
int n, mx;
VVI a;
VI w;
VB v;
VI sz;
void CitesteDate();
void Dfs(int x);
int main()
{
CitesteDate();
Dfs(1);
cout << mx;
}
void Dfs(int x)
{
v[x] = true;
sz[x] = w[x];
for (int y : a[x])
{
if (v[y]) continue;
Dfs(y);
if (w[y] > 0)
sz[x] += sz[y];
}
mx = max(sz[x], mx);
}
void CitesteDate()
{
cin >> n;
w = sz = VI(n + 1);
a = VVI(n + 1);
v = VB(n + 1);
for(int i = 1; i <= n; ++i)
cin >> w[i];
for (int x, y; cin >> x >> y; )
a[x].push_back(y);
}