結果

問題 No.1227 I hate ThREE
ユーザー chocoruskchocorusk
提出日時 2020-09-11 22:56:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,596 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 130,748 KB
実行使用メモリ 19,540 KB
最終ジャッジ日時 2023-08-27 16:19:19
合計ジャッジ時間 3,888 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 11 ms
19,104 KB
testcase_04 AC 11 ms
19,056 KB
testcase_05 AC 13 ms
18,472 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
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 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
int 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