結果

問題 No.1227 I hate ThREE
ユーザー chocoruskchocorusk
提出日時 2020-09-11 23:05:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,595 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 130,792 KB
実行使用メモリ 19,404 KB
最終ジャッジ日時 2023-08-30 14:45:44
合計ジャッジ時間 4,536 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 14 ms
18,896 KB
testcase_04 AC 14 ms
18,980 KB
testcase_05 AC 17 ms
18,372 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 9 ms
8,624 KB
testcase_09 AC 8 ms
8,684 KB
testcase_10 AC 5 ms
6,404 KB
testcase_11 AC 70 ms
18,472 KB
testcase_12 AC 78 ms
19,152 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 8 ms
8,576 KB
testcase_15 AC 12 ms
8,704 KB
testcase_16 AC 33 ms
13,244 KB
testcase_17 AC 18 ms
10,880 KB
testcase_18 AC 49 ms
15,544 KB
testcase_19 AC 37 ms
13,376 KB
testcase_20 AC 55 ms
15,668 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 40 ms
15,464 KB
testcase_23 AC 138 ms
19,200 KB
testcase_24 AC 120 ms
19,404 KB
testcase_25 AC 144 ms
19,244 KB
testcase_26 AC 88 ms
18,452 KB
testcase_27 AC 95 ms
19,012 KB
testcase_28 AC 97 ms
19,080 KB
testcase_29 AC 97 ms
19,120 KB
testcase_30 AC 90 ms
18,700 KB
testcase_31 AC 92 ms
18,644 KB
testcase_32 AC 98 ms
19,300 KB
testcase_33 AC 88 ms
18,716 KB
testcase_34 AC 94 ms
18,860 KB
testcase_35 AC 87 ms
18,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll dp[1010][2020];
vector<int> g[1010];
int c;
ll p2[1010];
int par[1010];
void dfs(int x, int p){
	par[x]=p;
	for(auto y:g[x]){
		if(y==p) continue;
		dfs(y, x);
	}
}
ll solve(int x, int v){
	if(dp[x][v]!=-1) return dp[x][v];
	if(v>=c) return dp[x][v]=0;
	ll ret=1;
	for(auto y:g[x]){
		if(y==par[x]) continue;
		ll s=0;
		if(v-1>=0) s+=solve(y, v-1);
		if(v+1<c) s+=solve(y, v+1);
		(ret*=s)%=MOD;
	}
	return dp[x][v]=ret;
}
int main()
{
	int n, c0;
	cin>>n>>c0;
	for(int i=0; i<n-1; i++){
		int a, b; cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1);
	ll ans=0;
	p2[0]=1;
	for(int i=1; i<=n; i++) p2[i]=p2[i-1]*2%MOD;
	for(int r=0; r<3; r++){
		c=(c0-r-1)/3+1;
		for(int j=0; j<n; j++) for(int i=0; i<=2*(n-1); i++) dp[j][i]=-1;
		for(int i=0; i<n; i++) solve(0, i);
		for(int i=0; i<min(c, n); i++){
			(ans+=dp[0][i])%=MOD;
		}
		for(int i=0; i<n && c-1-i>=min(c, n); i++){
			(ans+=dp[0][i])%=MOD;
		}
		if(n-1<c-n){
			(ans+=p2[n-1]*(c-2*n))%=MOD;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0