結果

問題 No.1227 I hate ThREE
ユーザー tyawanmusityawanmusi
提出日時 2020-07-28 16:35:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 986 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 124,720 KB
最終ジャッジ日時 2024-04-27 13:37:19
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,908 KB
testcase_01 AC 40 ms
52,760 KB
testcase_02 AC 41 ms
52,724 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 43 ms
52,768 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
sys.setrecursionlimit(2000)
input = sys.stdin.readline
mod = 10 ** 9 + 7

n, c = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  edge[a].append(b)
  edge[b].append(a)

def solve(x):
  minc = min(2 * n - 1, x)
  dp = [minc * [1] for _ in range(n)]

  def dfs(r, node):
    for mode in edge[node]:
      if mode == r:continue
      dpsub = dfs(node, mode)
      dp[node][0] = (dp[node][0] * dpsub[1]) % mod
      dp[node][minc - 1] = (dp[node][minc - 1] * dpsub[minc - 2]) % mod
      for i in range(1, minc - 1):
        dp[node][i] = (dp[node][i] * (dpsub[i - 1]+dpsub[i + 1])) % mod
    return dp[node]

  lastdp = dfs(-1, 0)

  if minc == x:
    return sum(lastdp)
  else:
    return sum(lastdp) + (x - minc) * lastdp[minc // 2]
ans1 = solve((c + 2) // 3) if c >= 4 else 0
ans2 = solve((c + 1) // 3) if c >= 5 else 0
ans3 = solve(c // 3)       if c >= 6 else 0
print(ans1 + ans2 + ans3)
0