結果

問題 No.1227 I hate ThREE
ユーザー 👑 NachiaNachia
提出日時 2020-10-03 17:49:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,155 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 168,060 KB
実行使用メモリ 27,224 KB
最終ジャッジ日時 2023-09-25 05:32:23
合計ジャッジ時間 3,420 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
24,456 KB
testcase_04 AC 7 ms
24,448 KB
testcase_05 AC 8 ms
11,672 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 8 ms
11,588 KB
testcase_09 AC 7 ms
11,912 KB
testcase_10 AC 6 ms
9,588 KB
testcase_11 AC 16 ms
25,940 KB
testcase_12 AC 18 ms
27,068 KB
testcase_13 AC 4 ms
7,472 KB
testcase_14 AC 7 ms
11,772 KB
testcase_15 AC 8 ms
13,672 KB
testcase_16 AC 12 ms
17,736 KB
testcase_17 AC 9 ms
15,684 KB
testcase_18 AC 14 ms
21,888 KB
testcase_19 AC 12 ms
19,776 KB
testcase_20 AC 14 ms
21,900 KB
testcase_21 AC 3 ms
4,808 KB
testcase_22 AC 13 ms
19,840 KB
testcase_23 AC 17 ms
26,532 KB
testcase_24 AC 18 ms
26,904 KB
testcase_25 AC 18 ms
27,224 KB
testcase_26 AC 17 ms
25,924 KB
testcase_27 AC 18 ms
26,496 KB
testcase_28 AC 19 ms
26,960 KB
testcase_29 AC 18 ms
26,756 KB
testcase_30 AC 17 ms
26,060 KB
testcase_31 AC 17 ms
25,996 KB
testcase_32 AC 18 ms
26,712 KB
testcase_33 AC 17 ms
25,928 KB
testcase_34 AC 18 ms
26,316 KB
testcase_35 AC 17 ms
25,928 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