#include <bits/stdc++.h>   using namespace std;   int num[300005];   long long dp[300005], ans = -LONG_LONG_MAX;   vector<int> G[300005];   int cnt = 0;   void dfs(int now, int fa) {     for (int k : G[now]) {       if (k != fa) {         dfs(k, now);         dp[now] += max((long long)0, dp[k]);       }     }     ans = max(ans, dp[now]);   }   void dfs2(int now, int fa) {     for (int k : G[now]) {       if (k != fa) {         dfs2(k, now);         dp[now] += max((long long)0, dp[k]);       }     }     if (dp[now] == ans) {       dp[now] = 0;       cnt++;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> num[i];       dp[i] = num[i];     }     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       G[x].push_back(y);       G[y].push_back(x);     }     dfs(1, -1);     for (int i = 1; i <= n; i++) dp[i] = num[i];     dfs2(1, -1);     cout << cnt * ans <<     << cnt;   }   