結果

問題 No.1227 I hate ThREE
ユーザー leaf_1415leaf_1415
提出日時 2020-09-11 22:09:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 3,051 ms
コンパイル使用メモリ 77,116 KB
実行使用メモリ 62,160 KB
最終ジャッジ日時 2023-08-30 14:36:18
合計ジャッジ時間 5,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 15 ms
58,948 KB
testcase_04 AC 14 ms
59,112 KB
testcase_05 AC 14 ms
10,092 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 55 ms
24,032 KB
testcase_09 AC 49 ms
21,792 KB
testcase_10 AC 36 ms
17,944 KB
testcase_11 AC 154 ms
60,728 KB
testcase_12 AC 164 ms
62,096 KB
testcase_13 AC 11 ms
11,536 KB
testcase_14 AC 24 ms
21,980 KB
testcase_15 AC 30 ms
25,892 KB
testcase_16 AC 46 ms
40,228 KB
testcase_17 AC 36 ms
32,040 KB
testcase_18 AC 54 ms
46,380 KB
testcase_19 AC 48 ms
42,344 KB
testcase_20 AC 57 ms
48,580 KB
testcase_21 AC 7 ms
7,532 KB
testcase_22 AC 48 ms
42,280 KB
testcase_23 AC 72 ms
61,272 KB
testcase_24 AC 71 ms
62,140 KB
testcase_25 AC 73 ms
62,160 KB
testcase_26 AC 71 ms
60,724 KB
testcase_27 AC 73 ms
61,048 KB
testcase_28 AC 73 ms
61,936 KB
testcase_29 AC 73 ms
61,852 KB
testcase_30 AC 71 ms
60,800 KB
testcase_31 AC 71 ms
60,720 KB
testcase_32 AC 73 ms
61,736 KB
testcase_33 AC 71 ms
60,784 KB
testcase_34 AC 72 ms
60,856 KB
testcase_35 AC 70 ms
60,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define PI 3.1415926535897932384626433832795028841971
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, C, M;
vector<llint> G[1005];
llint dp[1005][7505];

void dfs(int v, int p)
{
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i] == p) continue;
		dfs(G[v][i], v);
	}
	
	for(int j = 1; j <= M; j++){
		dp[v][j] = 1;
		for(int i = 0; i < G[v].size(); i++){
			llint u = G[v][i];
			if(u == p) continue;
			llint sum = 0;
			if(j+3 <= M) (sum += dp[u][j+3]) %= mod;
			if(j-3 >= 1) (sum += dp[u][j-3]) %= mod;
			dp[v][j] *= sum, dp[v][j] %= mod;
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> C;
	M = min(C, 7000LL);
	llint u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1);
	
	/*for(int i = 1; i <= n; i++){
		for(int j = 1; j <= M; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 1; i <= M; i++) ans += dp[1][i], ans %= mod;
	if(C > 7000) ans += dp[1][3500] * (C - 7000) % mod, ans %= mod;
	
	cout << ans << endl;
	
	return 0;
}
0