結果

問題 No.1227 I hate ThREE
ユーザー 沙耶花沙耶花
提出日時 2020-09-11 23:45:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,797 bytes
コンパイル時間 2,544 ms
コンパイル使用メモリ 221,520 KB
実行使用メモリ 50,816 KB
最終ジャッジ日時 2024-06-08 17:02:59
合計ジャッジ時間 6,110 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 104 ms
49,664 KB
testcase_04 AC 103 ms
50,176 KB
testcase_05 AC 99 ms
48,384 KB
testcase_06 AC 2 ms
5,376 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 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 <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000
int N;
vector<vector<int>> E;
int C;
vector<vector<mint>> dp1;
vector<vector<mint>> dp2;
vector<vector<mint>> dp3;
int t0,t1,t2;
void dfs(int now,int p){
	rep(i,min(C,3000)){
		dp1[now][i] = 1;
	}
	rep(i,min(C-3000,3000)){
		dp2[now][i] = 1;
	}
	
	dp3[now][0] = t0;
	dp3[now][1] = t1;
	dp3[now][2] = t2;
	rep(i,dp1[now].size()){
		dp3[now][i%3]-=dp1[now][i];
	}
	rep(i,dp2[now].size()){
		dp3[now][(C-1-i)%3]-=dp2[now][i];
	}
	
	rep(i,E[now].size()){
		int to  =E[now][i];
		if(to==p)continue;
		dfs(to,now);
		rep(j,dp1[now].size()){
			mint t = 0;
			if(j-3>=0)t += dp1[to][j-3];
			if(j+3<dp1[now].size())t += dp1[to][j+3];
			else t += dp3[to][j%3];
			dp1[now][j] *= t;
		}
		rep(j,dp2[now].size()){
			mint t = 0;
			if(j-3>=0)t += dp2[to][j-3];
			if(j+3<dp2[now].size())t += dp2[to][j+3];
			else t += dp3[to][(C-1-j)%3];
			dp2[now][j] *= t;
		}
		rep(j,3){
			dp3[now][j] *= dp3[to][j]*2;
		}
	}
	
}

int main(){
	
	cin>>N>>C;
	t0 = (C+2)/3;
	t1 = (C+1)/3;
	t2 = C/3;
	E.resize(N,vector<int>());
	rep(i,N-1){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	dp1.resize(N,vector<mint>(6000,0));
	dp2.resize(N,vector<mint>(6000,0));
	dp3.resize(N,vector<mint>(3,0));
	
	dfs(0,-1);
	
	mint ans = 0;
	rep(i,6000){
		ans += dp1[0][i];
		ans += dp2[0][i];
	}
	ans += dp3[0][0];
	ans += dp3[0][1];
	ans += dp3[0][2];
	/*
	rep(i,N){
		rep(j,3){
			cout<<dp3[i][j].val()<<',';
		}
		cout<<endl;
	}*/
	
	
	cout<<ans.val()<<endl;
			
    return 0;
}
0