結果

問題 No.1227 I hate ThREE
ユーザー tyawanmusityawanmusi
提出日時 2020-09-12 03:00:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,150 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 91,508 KB
最終ジャッジ日時 2023-08-28 15:00:40
合計ジャッジ時間 8,111 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,864 KB
testcase_01 AC 18 ms
7,832 KB
testcase_02 AC 17 ms
7,796 KB
testcase_03 AC 46 ms
11,116 KB
testcase_04 AC 41 ms
9,252 KB
testcase_05 AC 111 ms
11,140 KB
testcase_06 AC 16 ms
7,860 KB
testcase_07 AC 17 ms
7,756 KB
testcase_08 AC 377 ms
17,712 KB
testcase_09 AC 294 ms
15,600 KB
testcase_10 AC 176 ms
12,612 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 初期設定
import sys
sys.setrecursionlimit(2000)
input = sys.stdin.readline
mod = 10**9+7

# 入力 + Cを圧縮
n, c = map(int, input().split())
minc = min(n * 10 - 5, c)
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)

# dp初期化(初期値は1です)
dp = [minc * [1] for _ in range(n)]

# 再帰で実装します
# 返り値はdp_v
def dfs(r, v):
  # vの親がr、vの子がu
  for u in edge[v]:
    if r == u:
      continue
    # dp_uを取得
    dp_u = dfs(v, u)
    for i in range(minc):
      # dp_{u,i-3} + dp_{u,i+3}を求める
      f = 0
      if i > 2:
        f += dp_u[i - 3]
      if i < minc - 3:
        f += dp_u[i + 3]
      
      # かける
      # p_v=iにすることが不可能な場合、f=0になる子が存在するのでこのままでよいです
      dp[v][i] *= f
      dp[v][i] %= mod
  return dp[v]

# 頂点1を根としてDFS、dp_1を取得
rootdp = dfs(-1, 0)

# rootdpの総和に加え、Cを圧縮しただけansに加算
ans = sum(rootdp)
ans += rootdp[minc // 2] * (c - minc)
print(ans % mod)
0