#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int INF = 0x7fffffff;   vector<int> G[maxn];   long long weight[maxn];   long long dp[maxn];   int ans;   long long maxsum = -INF;   void dfs(int now, int fa) {     dp[now] = weight[now];     for (int v : G[now]) {       if (v != fa) {         dfs(v, now);         if (dp[v] > 0) dp[now] += dp[v];       }     }     maxsum = max(maxsum, dp[now]);   }   void dfs2(int now, int fa) {     dp[now] = weight[now];     for (int v : G[now]) {       if (v != fa) {         dfs2(v, now);         if (dp[v] > 0) dp[now] += dp[v];       }     }     if (dp[now] == maxsum) {       ans++;       dp[now] = 0;     }   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> weight[i];     int from, to;     for (int i = 2; i <= n; ++i) {       cin >> from >> to;       G[from].push_back(to);       G[to].push_back(from);     }     dfs(1, 0);     dfs2(1, 0);     cout << maxsum * ans <<     << ans << endl;     return 0;   }   