結果

問題 No.1227 I hate ThREE
ユーザー chielochielo
提出日時 2020-09-12 01:12:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,337 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 200,548 KB
実行使用メモリ 50,848 KB
最終ジャッジ日時 2023-08-30 14:54:33
合計ジャッジ時間 4,479 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 12 ms
49,056 KB
testcase_04 AC 11 ms
48,776 KB
testcase_05 AC 12 ms
47,104 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 10 ms
18,720 KB
testcase_09 AC 8 ms
16,816 KB
testcase_10 AC 6 ms
14,380 KB
testcase_11 AC 43 ms
48,616 KB
testcase_12 AC 48 ms
50,720 KB
testcase_13 AC 3 ms
8,032 KB
testcase_14 AC 8 ms
16,664 KB
testcase_15 AC 11 ms
20,980 KB
testcase_16 AC 22 ms
31,752 KB
testcase_17 AC 15 ms
25,164 KB
testcase_18 AC 29 ms
37,944 KB
testcase_19 AC 24 ms
33,644 KB
testcase_20 AC 31 ms
40,020 KB
testcase_21 AC 2 ms
5,884 KB
testcase_22 AC 23 ms
33,664 KB
testcase_23 AC 45 ms
50,624 KB
testcase_24 AC 49 ms
50,600 KB
testcase_25 AC 47 ms
50,692 KB
testcase_26 AC 44 ms
48,600 KB
testcase_27 AC 47 ms
50,552 KB
testcase_28 AC 48 ms
50,624 KB
testcase_29 AC 48 ms
50,592 KB
testcase_30 AC 46 ms
50,656 KB
testcase_31 AC 46 ms
50,716 KB
testcase_32 AC 48 ms
50,848 KB
testcase_33 AC 46 ms
50,848 KB
testcase_34 AC 47 ms
50,656 KB
testcase_35 AC 45 ms
48,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

const int maxn = 1e3 + 3;
using ll = long long;
const ll mo = 1e9 + 7;

int n, C, p[maxn];
std::vector<int> E[maxn];
ll dp[maxn][maxn * 3 * 2 + 3];

void dfs(int u) {
    for(int i = 1; i <= C && i <= n * 3 * 2 + 2; ++i) {
        dp[u][i] = 1;
    }
    for(auto &&v : E[u]) {
        if(v == p[u])
            continue;
        p[v] = u;
        dfs(v);
        for(int i = 1; i <= C && i <= n * 3 * 2 + 2; ++i) {
            ll wu = (i - 3 >= 1) ? dp[v][i - 3] : 0ll;
            ll wv = (i + 3 <= C && i + 3 <= n * 3 * 2 + 2) ? dp[v][i + 3] : 0ll;
            dp[u][i] = dp[u][i] * ((wu + wv) % mo) % mo;
        }
    }
}

int main() {
    scanf("%d%d", &n, &C);
    for(int i = 0; i < n - 1; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        E[u].push_back(v);
        E[v].push_back(u);
    }
    dfs(1);
    ll ans = 0;
    if(C > n * 3 * 2 + 2) {
        for(int i = 1; i <= n * 3; ++i) {
            ans = (ans + dp[1][i]) % mo;
        }
        for(int i = 1; i <= n * 3; ++i) {
            ans = (ans + dp[1][n * 3 * 2 + 2 - i + 1]) % mo;
        }
        ans = (ans + dp[1][n * 3 + 1] * (C - n * 3 * 2) % mo) % mo;
    } else {
        for(int i = 1; i <= C; ++i) {
            ans = (ans + dp[1][i]) % mo;
        }
    }
    printf("%lld\n", (ans % mo + mo) % mo);
    return 0;
}
0