#include <stdio.h>
#include <stdlib.h>
int n, cnt = 0;
struct edge {
int to, next;
}e[400010];
int w[200010];
int head[200010];
int ans = 0, maxx = -1;
void addedge(int u, int v) {
e[++cnt].to = v;
e[cnt].next=head[u];
head[u]=cnt;
}
int main()
{
scanf("%d",&n);
for(int i = 1;i < n; i++) {
int u, v;
scanf("%d%d",&u,&v);
addedge(u,v), addedge(v, u);
}
for(int i = 1;i <= n; i++) {
scanf("%d",&w[i]);
}
for(int i = 1;i < n; i++) {
int max1=-1,max2=-1,t=0,wx;
for(int j = head[i];j;j=e[j].next) {
wx = w[e[j].to];
t = t+wx, t%=10007;
if(wx>max1) {
max2 = max1;
max1 = wx;
}
else if(wx>max2) {
max2=wx;
}
}
max1 *= max2;
if(max1 > maxx) maxx = max1;
for(int j = head[i];j;j=e[j].next) {
wx = w[e[j].to];
ans += wx*(t-wx), ans %= 10007;
}
}
ans = (ans + 10007)%10007;
printf("%d %d\n",maxx,ans);
return 0;
}
/**************************************************************
Problem: 2335
User: admin
Language: C
Result: Accepted
Time:369 ms
Memory:5832 kb
****************************************************************/