const m=10007;
type edge=record
v,next:longint;
end;
var i,j,k,n,p,end_,max1,max2,sum,tot,max0:longint;
w:array[1..200000]of longint;
e:array[1..400000]of edge;
d:array[1..200000]of longint;
first:array[1..200000]of longint;
function max(a,b:longint):longint;begin if a>b then exit(a);exit(b);end;
procedure add(x,y:longint);
begin
inc(end_);
e[end_].v:=y;
e[end_].next:=first[x];
first[x]:=end_;
end;
procedure init;
var u,v:longint;
begin
readln(n);
end_:=0;
for i:=1 to n do first[i]:=-1;
for i:=1 to n-1 do
begin
readln(u,v);
add(u,v);
add(v,u);
end;
for i:=1 to n do
begin
read(w[i]);
end;
end;
begin
init;
max0:=-1;
for i:=1 to n do
begin
j:=first[i];
max1:=-1;max2:=-1;sum:=0;p:=0;
while j<>-1 do
begin
inc(p);d[p]:=w[e[j].v];
sum:=(sum+d[p])mod m;
tot:=(tot-d[p]*d[p]+m)mod m;
if d[p]>max1 then begin max2:=max1;max1:=d[p]; end
else if d[p]>max2 then max2:=d[p];
j:=e[j].next;
end;
if p>0 then begin tot:=(tot+sum*sum)mod m; end;
if tot<0 then tot:=tot+m;
max0:=max(max0,max1*max2);
end;
writeln(max0,' ',tot);
end.
/**************************************************************
Problem: 2335
User: admin
Language: Pascal
Result: Wrong Answer
****************************************************************/