闰土,70WA
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n, x, y, v[500001], head[500001], nxt[500001], cnt, w[200001];
int sum, maxx;
void add(int a, int b) {
v[++cnt] = b;
nxt[cnt] = head[a];
head[a] = cnt;
}
int main() {
scanf("%d", &n);
for(int i = 1; i < n; i++) {
scanf("%d%d", &x, &y);
add(x, y);
add(y, x);
}
for(int i = 1; i <= n; i++) scanf("%d", &w[i]);
for(int i = 1; i <= n; i++) {
int f = 0, maxn = 0;
for(int j = head[i]; j; j = nxt[j]) {
sum += (f * w[v[j]]) % 10007;
f += w[v[j]];
maxx = max(maxx, maxn * w[v[j]]);
maxn = max(maxn, w[v[j]]);
}
}
cout << maxx << " " << sum * 2 % 10007;
return 0;
}