- 问答
- 2015-08-22 21:52:37 @
#include<cstdio>
#include<cstring>
#include<algorithm>
int n,tot=0,first[200001],next[200001],v[200001],sum[200001],w[200001],ans1=0,maxn[200001];
int ans2=0;
bool visit[200001];
using namespace std;
void build(int x,int y){
next[++tot]=first[x];
first[x]=tot;
v[tot]=y;
next[++tot]=first[y];
first[y]=tot;
v[tot]=x;
}
void dfs(int x){
int t=first[x];
visit[x]=true;
while(t!=0){
if(not visit[v[t]]){
sum[x]+=w[v[t]];
sum[v[t]]+=w[x];
maxn[x]=max(maxn[x],w[v[t]]);
dfs(v[t]);
ans1=max(ans1,w[x]*maxn[v[t]]);
}
t=next[t];
}
return;
}
void solve(int x){
int t=first[x];
visit[x]=true;
while(t!=0){
if(not visit[v[t]]){
solve(v[t]);
}
ans2+=(w[v[t]]*(sum[x]-w[v[t]]))%10007;
t=next[t];
}
return;
}
int main(){
scanf("%d",&n);
memset(first,0,sizeof(first));
memset(next,0,sizeof(next));
memset(sum,0,sizeof(sum));
memset(maxn,0,sizeof(maxn));
memset(visit,false,sizeof(visit));
for(int i=1;i<=n-1;i++)
{
int x,y;
scanf("%d%d",&x,&y);
build(x,y);
}
for(int i=1;i<=n;i++)
scanf("%d",&w[i]);
dfs(1);
memset(visit,false,sizeof(visit));
solve(1);
printf("%d %d\n",ans1,ans2);
return 0;
}
3 条评论
-
t14t41t LV 10 @ 2015-08-24 08:10:41
我估计是“not”的原因,改成“!”再试一试吧。
-
2015-08-23 15:35:22@
include前面有#吗
-
2015-08-23 15:34:40@
#include
- 1