Pagini recente » warm-up-2020/solutii/cuantictiori | Problema satisfiabilităţii formulelor logice de ordinul doi | Cod sursa (job #2707589) | Istoria paginii runda/brasov_12_jr/clasament | Cod sursa (job #2012306)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("asmax.in");
ofstream fout("asmax.out");
using VI = vector<int>;
vector<bool> v;
VI smax, val;
vector<VI> G;
int n;
void ReadGraph();
void Df(int x);
int main()
{
ReadGraph();
Df(1);
int res = 0;
for (const int& x : smax)
res = max(res, x);
fout << res;
fin.close();
fout.close();
}
void Df(int x)
{
v[x] = true;
smax[x] = val[x];
for (const int& y : G[x])
{
if (v[y]) continue;
Df(y);
if (smax[y] > 0)
smax[x] += smax[y];
}
}
void ReadGraph()
{
fin >> n;
v = vector<bool>(n + 1);
val = smax = VI(n + 1);
G = vector<VI>(n + 1);
for (int i = 1; i <= n; ++i)
fin >> val[i];
int x, y;
while (fin >> x >> y)
{
G[x].push_back(y);
G[y].push_back(x);
}
}