結果

問題 No.1227 I hate ThREE
ユーザー rlangevinrlangevin
提出日時 2024-01-22 12:18:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,691 ms / 2,000 ms
コード長 1,200 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 131,620 KB
最終ジャッジ日時 2024-01-22 12:19:04
合計ジャッジ時間 17,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 34 ms
53,460 KB
testcase_03 AC 75 ms
76,548 KB
testcase_04 AC 88 ms
76,556 KB
testcase_05 AC 80 ms
78,156 KB
testcase_06 AC 34 ms
53,460 KB
testcase_07 AC 41 ms
61,724 KB
testcase_08 AC 181 ms
94,244 KB
testcase_09 AC 173 ms
92,068 KB
testcase_10 AC 139 ms
87,864 KB
testcase_11 AC 465 ms
127,652 KB
testcase_12 AC 471 ms
130,340 KB
testcase_13 AC 103 ms
81,564 KB
testcase_14 AC 182 ms
91,556 KB
testcase_15 AC 223 ms
96,292 KB
testcase_16 AC 347 ms
108,836 KB
testcase_17 AC 255 ms
100,644 KB
testcase_18 AC 363 ms
115,620 KB
testcase_19 AC 338 ms
110,500 KB
testcase_20 AC 406 ms
117,412 KB
testcase_21 AC 86 ms
78,620 KB
testcase_22 AC 342 ms
111,140 KB
testcase_23 AC 1,660 ms
130,468 KB
testcase_24 AC 1,308 ms
130,980 KB
testcase_25 AC 1,691 ms
131,620 KB
testcase_26 AC 475 ms
127,908 KB
testcase_27 AC 495 ms
129,700 KB
testcase_28 AC 487 ms
130,340 KB
testcase_29 AC 491 ms
130,340 KB
testcase_30 AC 475 ms
128,548 KB
testcase_31 AC 475 ms
128,548 KB
testcase_32 AC 503 ms
130,084 KB
testcase_33 AC 471 ms
128,292 KB
testcase_34 AC 487 ms
129,316 KB
testcase_35 AC 475 ms
128,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def non_rec_dfs(G, s):
    stack = [s]
    N = len(G)
    par = [-1] * N
    sz = [1] * N
    dp = [[1] * M for _ in range(N)]
    ans = 0
    while stack:
        u = stack.pop()
        if u >= 0:
            stack.append(~u)
            for v in G[u]:
                if v == par[u]:
                    continue
                par[v] = u
                stack.append(v)
        else:
            u = ~u
            for i in range(M):
                for v in G[u]:
                    temp = 0
                    if v == par[u]:
                        continue
                    sz[u] += sz[v]
                    if i >= 3:
                        temp += dp[v][i - 3]
                    if i < M - 3:
                        temp += dp[v][i + 3]
                    dp[u][i] *= temp
                    dp[u][i] %= mod
                
    return dp[0]


N, C = map(int, input().split())
M = min(7000, C)
mod = 10 ** 9 + 7
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append(v)
    G[v].append(u)
    
dp = non_rec_dfs(G, 0)
ans = sum(dp) + dp[M//2] * (C - M)
print(ans%mod)
0