結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 33 ms
53,460 KB
testcase_03 AC 76 ms
76,548 KB
testcase_04 AC 85 ms
76,556 KB
testcase_05 AC 78 ms
78,156 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

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] * (M - C)
print(ans%mod)
0