結果

問題 No.1227 I hate ThREE
ユーザー msm1993msm1993
提出日時 2020-10-08 10:04:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 1,543 ms
コンパイル使用メモリ 168,224 KB
実行使用メモリ 27,100 KB
最終ジャッジ日時 2023-09-27 11:41:18
合計ジャッジ時間 4,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 6 ms
24,368 KB
testcase_04 AC 6 ms
24,368 KB
testcase_05 AC 7 ms
11,676 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 7 ms
11,880 KB
testcase_09 AC 7 ms
11,628 KB
testcase_10 AC 6 ms
9,496 KB
testcase_11 AC 16 ms
26,068 KB
testcase_12 AC 16 ms
26,916 KB
testcase_13 AC 5 ms
7,524 KB
testcase_14 AC 7 ms
11,592 KB
testcase_15 AC 8 ms
13,652 KB
testcase_16 AC 10 ms
17,824 KB
testcase_17 AC 8 ms
15,668 KB
testcase_18 AC 12 ms
21,896 KB
testcase_19 AC 12 ms
19,744 KB
testcase_20 AC 13 ms
21,924 KB
testcase_21 AC 3 ms
4,788 KB
testcase_22 AC 12 ms
19,780 KB
testcase_23 AC 15 ms
26,500 KB
testcase_24 AC 18 ms
26,896 KB
testcase_25 AC 16 ms
27,100 KB
testcase_26 AC 16 ms
25,936 KB
testcase_27 AC 17 ms
26,404 KB
testcase_28 AC 17 ms
26,756 KB
testcase_29 AC 16 ms
26,916 KB
testcase_30 AC 15 ms
26,052 KB
testcase_31 AC 16 ms
26,008 KB
testcase_32 AC 17 ms
26,728 KB
testcase_33 AC 15 ms
25,916 KB
testcase_34 AC 16 ms
26,412 KB
testcase_35 AC 16 ms
25,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M = 1000000007;

int N;
int C;
vector<int> E[1000];
int P[1000];

ULL dp[1000][3001] = {};

void dfs(int p) {
    rep(i, min((C + 1) / 2, 3001)) dp[p][i] = 1;
    for (int e : E[p]) {
        if (P[p] == e) continue;
        P[e] = p;
        dfs(e);
        rep(i, min((C + 1) / 2, 3)) dp[p][i] = dp[p][i] * dp[e][min(min(C - i - 4, i + 3), 3000)] % M;
        for (int i = 3; i < min((C + 1) / 2, 3000); i++)
            dp[p][i] = dp[p][i] * (dp[e][i - 3] + dp[e][min(min(C - i - 4, i + 3), 3000)]) % M;
        dp[p][3000] = dp[p][3000] * dp[e][3000] * 2 % M;
    }
}

int main() {
    cin >> N >> C;
    rep(i, N - 1) {
        int u, v; cin >> u >> v; u--; v--;
        E[u].push_back(v);
        E[v].push_back(u);
    }

    rep(i, N) P[i] = -1;

    dfs(0);

    ULL ans = 0;
    rep(i, min(C / 2, 3000)) ans += dp[0][i] * 2;
    if (C <= 5999) if (C % 2 == 1) ans += dp[0][C / 2];
    if (C >= 6000) ans += dp[0][3000] * (C - 6000) % M;
    ans %= M;

    cout << ans << endl;

    return 0;
}
0