求救
#include<cstdio>
using namespace std;
const int maxn=2e5+3;
const int mod=1e4+7;
struct edge
{
int to,next;
}e[maxn];
long long n,head[maxn],num_edge,w[maxn],sum,maxw;
inline void add_edge(int from,int to)
{
e[++num_edge].next=head[from];
e[num_edge].to=to;
head[from]=num_edge;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<n;i++)
{
int u,v;
scanf("%d%d",&u,&v);
add_edge(u,v);
add_edge(v,u);
}
for(int i=1;i<=n;i++) scanf("%d",&w[i]);
for(int k=1;k<=n;k++)
{
long long section_sum=0,section_max=0;
for(int i=head[k];i;i=e[i].next)
{
if(maxw<section_max*w[e[i].to])maxw=section_max*w[e[i].to];
if(section_max<w[e[i].to])section_max=w[e[i].to];
sum=(sum+section_sum*w[e[i].to]%mod)%mod;
section_sum=(section_sum+w[e[i].to])%mod;
}
}
printf("%lld %lld",maxw,(sum*2)%mod);
return 0;
}