/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 5ms 344.0 KiB
#2 Wrong Answer 4ms 356.0 KiB
#3 Wrong Answer 4ms 368.0 KiB
#4 Wrong Answer 12ms 396.0 KiB
#5 Wrong Answer 9ms 384.0 KiB
#6 Wrong Answer 10ms 484.0 KiB
#7 Wrong Answer 11ms 384.0 KiB
#8 Wrong Answer 13ms 512.0 KiB
#9 Wrong Answer 12ms 488.0 KiB
#10 Wrong Answer 12ms 476.0 KiB

代码

#include<bits/stdc++.h>
#define LL long long
const LL mod=1e9+7;
inline void read(LL &a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
inline void write(LL a)
{
	if(a<0){putchar('-');a=-a;}
	if(a>9)write(a/10);
	putchar(a%10+'0');
}
#define maxn 2001
LL ans=0,n,k,d=0,num[maxn],point[maxn],next[maxn],to[maxn],father[maxn],step[maxn];
inline void add(LL a,LL b)
{
	next[++d]=point[a];
	point[a]=d;
	to[d]=b;
}
inline LL fast_pow(LL a,LL b)
{
	if(b==0)return 1;
	LL base=a,ans=1;
	while(b)
	{
		if(b&1)ans=ans*base%mod;
		base=base*base%mod;
		b>>=1;
	}
	return ans;
}
inline LL dfs1(LL p)
{
	LL side=point[p];
	num[p]=1;
	while(side)
	{
		if(to[side]!=father[p])
		{
			father[to[side]]=p;
			num[p]+=dfs1(to[side]);
		}
		side=next[side];
	}
	return num[p];
}
inline void dfs2(LL p)
{
	for(LL i=1;i<=k&&i<=num[p];i++)
		if(k-i<=n-num[p]&&k-i)
		{
			ans=(ans
				+step[num[p]]*fast_pow(step[i]*(num[p]-i)%mod,mod-2)%mod
				+step[n-num[p]]*fast_pow(step[k-i]*step[n-num[p]-k+i],mod-2)%mod
				)%mod;
		}
	LL side=point[p];
	while(side)
	{
		if(to[side]!=father[p])dfs2(to[side]);
		side=next[side];
	}
}
int main()
{
	read(n);read(k);
	LL st=1;
	for(LL i=1;i<=n;i++)st=step[i]=i*st%mod;
	memset(num,0,sizeof(num));
	memset(point,0,sizeof(point));
	LL u,v;
	for(LL i=1;i<=n-1;i++){read(u);read(v);add(u,v);add(v,u);}
	dfs1(1);
	dfs2(1);
	write(ans);
	return 0;
}

信息

递交者
类型
递交
题目
月上树(原创)
题目数据
下载
语言
C++
递交时间
2017-11-07 10:04:41
评测时间
2017-11-07 15:17:54
评测机
分数
0
总耗时
96ms
峰值内存
512.0 KiB