結果

問題 No.1227 I hate ThREE
ユーザー tyawanmusityawanmusi
提出日時 2020-07-28 16:33:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 165,248 KB
最終ジャッジ日時 2024-04-27 13:37:51
合計ジャッジ時間 13,899 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 27 ms
11,008 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 26 ms
10,880 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

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]


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)

c1 = (c + 2) // 3
c2 = (c + 1) // 3
c3 = c // 3

ans1 = solve(c1)

if c1 == c2:
  ans2 = ans1
elif c2 == 1:
  ans2 = 0
else:
  ans2 = solve(c2)
 
if c2 == c3:
  ans3 = ans2
elif c3 == 1:
  ans3 = 0
else:
  ans3 = solve(c3)


print(ans1 + ans2 + ans3)
0