#include <algorithm>
#include <climits>
#include <fstream>
#include <iostream>
#include <vector>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_cxx;

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pcc = pair<char, char>;
using pss = pair<string, string>;
using vi = vector<int>;
using vb = vector<bool>;
using vii = vi::iterator;

#define INF (1 << 30)
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define ms(name, val) memset(name, val, sizeof name)
#define np nullptr

ll ans = LLONG_MIN;
vector<int> a;
vector<ll> subtreeSum, subtreeMax;
vector<vector<int>> g;

void precalculate(int node, int parent) {
  subtreeSum[node] = a[node];

  for (const int &child : g[node]) {
    if (child == parent) continue;
    precalculate(child, node);
    subtreeSum[node] += subtreeSum[child];
    subtreeMax[node] = max(subtreeMax[node], subtreeMax[child]);
  }

  subtreeMax[node] = max(subtreeMax[node], subtreeSum[node]);
}

void solve(int node, int parent, ll maxOut) {
  if (maxOut != LLONG_MIN) {
    ans = max(ans, subtreeMax[node] + maxOut);  // (sum vs max) + maxOut
  }

  ll max1 = LLONG_MIN, max2 = LLONG_MIN;

  for (const int &child : g[node]) {
    if (child == parent) continue;

    if (subtreeMax[child] > max1) {
      max2 = max1;
      max1 = subtreeMax[child];
    } else if (subtreeMax[child] > max2) {
      max2 = subtreeMax[child];
    }
  }

  for (const int &child : g[node]) {
    if (child == parent) continue;

    if (subtreeMax[child] == max1)
      solve(child, node, max2);
    else
      solve(child, node, max1);
  }
}

int main() {
  ios_base::sync_with_stdio(0);

  std::istream& in = std::cin;
  int n;
  in >> n;

  a.resize(n);
  subtreeSum.resize(n);
  subtreeMax.assign(n, LLONG_MIN);
  g.resize(n);

  for (int i = 0; i < n; ++i) {
    in >> a[i];
  }

  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    in >> a >> b;
    --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  std::ostream& out = std::cout;
  precalculate(0, -1);
  solve(0, -1, LLONG_MIN);

  if (ans == LLONG_MIN) {
    cout << "Nemoguce\n";
  } else {
    cout << ans << '\n';
  }

  return 0;
}