Pagini recente » Cod sursa (job #2000908) | Cod sursa (job #286924) | Cod sursa (job #3221284) | Cod sursa (job #353731) | Cod sursa (job #3212748)
#include <fstream>
#include <climits>
#include <vector>
using namespace std;
const int nmax = 16005;
vector<int> v[nmax];
int val[nmax], dp[nmax];
void dfs(int node, int tactu_mare){
dp[node] = val[node];
for(int vec: v[node]){
if(vec != tactu_mare){
dfs(vec, node);
if(dp[vec] > 0){
dp[node] += dp[vec];
}
}
}
}
int main(){
ifstream f("asmax.in");
ofstream g("asmax.out");
int n, m;
f >> n >> m;
for(int i = 1; i <= n; i++){
f >> val[i];
}
for(int i = 1; i <= n; i++){
int x, y;
f >> x >> y;
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1, 0);
int sol = INT_MIN;
for(int i = 1; i <= n; i++){
sol = max(sol, dp[i]);
}
g << sol << '\n';
}