func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const long long INF = 1e18 + 10;   struct node {     int next, v;   } edge[maxn * 2 + 10];   int cnt, head[maxn], vis[maxn], pa[maxn];   long long sum[maxn], cost[maxn], a[maxn], ss[maxn];   queue<int> q;   int find(int x) {     if (x == pa[x]) return x;     return pa[x] = find(pa[x]);   }   void add2(int x, int y) {     x = find(x);     y = find(y);     pa[x] = y;     ss[y] += ss[x];   }   void dfs(int u, int fa) {     int i, v;     sum[u] = a[u];     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (v == fa) continue;       dfs(v, u);       if (sum[v] > 0) sum[u] += sum[v];     }   }   void dfs2(int u, int fa) {     int i, v;     if (u == 1) {       cost[u] = sum[u];       for (i = head[1]; i != -1; i = edge[i].next) {         v = edge[i].v;         dfs2(v, u);       }       return;     }     if (sum[u] <= 0) {       cost[u] = max(sum[u], sum[u] + cost[fa]);     } else {       long long tmp = cost[fa] - sum[u];       if (tmp > 0) {         cost[u] = sum[u] + tmp;         add2(u, fa);       } else {         cost[u] = sum[u];       }     }     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (fa == v) continue;       dfs2(v, u);     }   }   void add(int x, int y) {     edge[cnt].next = head[x];     edge[cnt].v = y;     head[x] = cnt++;   }   int main() {     int i, n;     long long ans, ret, s, u, v;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     cnt = 0;     memset(head, -1, sizeof(head));     for (i = 1; i <= n - 1; i++) {       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     for (i = 1; i <= n; i++) {       pa[i] = i;       ss[i] = a[i];     }     dfs(1, -1);     dfs2(1, -1);     ans = -INF;     for (i = 1; i <= n; i++) ans = max(ans, cost[i]);     if (ans <= 0) {       ret = 0;       s = 0;       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           ret++;           s += ans;         }       }       printf( %I64d %I64d n , s, ret);     } else {       ret = 0;       s = 0;       memset(vis, 0, sizeof(vis));       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           int tt = find(i);           if (!vis[tt] && ss[tt] == ans) {             ret++;             s += ans;             vis[tt] = 1;           }         }       }       printf( %I64d %I64d n , s, ret);     }     return 0;   }   