Pagini recente » Cod sursa (job #2633371) | Cod sursa (job #1518203) | Cod sursa (job #2236959) | Cod sursa (job #2681306) | Cod sursa (job #2566826)
#include <bits/stdc++.h>
#define FILE_NAME "asmax"
#define fast ios_base :: sync_with_stdio(0); cin.tie(0);
#pragma GCC optimize("O3")
#define NMAX 16010
using namespace std;
ifstream f(FILE_NAME ".in");
ofstream g(FILE_NAME ".out");
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pi;
typedef pair<ld,ld> pct;
const ll inf = 1LL << 60;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
void add(ll &a , ll b)
{
a += b;
a %= mod;
}
void sub(ll &a, ll b)
{
a = (a - b + mod) % mod;
}
int n, d[NMAX];
bitset <NMAX> viz, start[NMAX];
vector <int> G[NMAX];
void DFS(int nod)
{
viz[nod] = 1;
for(auto it : G[nod])
if(!viz[it])
{
DFS(it);
d[nod] = max(d[nod], d[nod] + d[it]);
}
}
int main()
{
f >> n;
for(int i = 1; i <= n; ++i)
f >> d[i];
for(int x,y, i = 1; i < n; ++i)
{
f >> x >> y;
G[x].push_back(y);
G[y].push_back(x);
}
DFS(1);
int ans = - (1 << 30);
for(int i = 1; i <= n; ++i)
ans = max(ans, d[i]);
g << ans;
f.close();
g.close();
return 0;
}