結果

問題 No.1075 木の上の山
ユーザー xllend3xllend3
提出日時 2020-06-05 22:48:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,445 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 182,332 KB
実行使用メモリ 21,920 KB
最終ジャッジ日時 2023-08-22 16:41:10
合計ジャッジ時間 5,738 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,320 KB
testcase_01 AC 4 ms
6,164 KB
testcase_02 AC 3 ms
6,096 KB
testcase_03 AC 3 ms
6,332 KB
testcase_04 AC 3 ms
6,036 KB
testcase_05 AC 3 ms
6,212 KB
testcase_06 AC 3 ms
6,344 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C,x,y;
vector<int>a[N];
int fa[N];
map<pair<pii,int>,vector<ll> >MA;
void dfs(int x,int f){
	for(auto i:a[x])if(i!=f)dfs(i,x);
	fa[x]=f;
}
void cal(int x,int y,int z){
	if(SZ(MA[mp(mp(x,y),z)]))return;
	vector<ll>V(m+1);
	if(y==0){
		rep(i,0,m)V[i]=1;
	}else{
		for(auto i:a[y])if(i!=x)cal(y,i,z);
		rep(i,1,m)V[i]=1;
		for(auto i:a[y])if(i!=x){
			rep(j,1,m)V[j]=V[j]*MA[mp(mp(y,i),z)][j]%mo;
		}
		rep(i,1,m)V[i]+=V[i-1];
	}
	MA[mp(mp(x,y),z)]=V;
}
ll calc(int x){
	cal(x,fa[x],0);
	cal(fa[x],x,1);
	ll ans=0;
	rep(i,1,m)ans=(ans+1ll*MA[mp(mp(x,fa[x]),0)][i-1]*(MA[mp(mp(fa[x],x),1)][i]-MA[mp(mp(fa[x],x),1)][i-1]))%mo;
	// printf("%d %lld\n",x,ans);
	return ans;
}
int main(){
#ifdef LOCAL
	freopen("F.in","r",stdin);//freopen("F.out","w",stdout);
#endif
	scanf("%d%d",&n,&m);
	rep(i,2,n)scanf("%d%d",&x,&y),a[x].pb(y),a[y].pb(x);
	dfs(1,0);
	ll ans=0;
	rep(i,1,n)ans=(ans+calc(i))%mo;
	cout<<ans<<endl;
	// for(auto i:MA){
	// 	printf("%d %d %d: ",i.X.X.X,i.X.X.Y,i.X.Y);
	// 	rep(j,0,m)printf("%lld ",i.Y[j]);puts("");
	// }
	return 0;
}
0