結果

問題 No.196 典型DP (1)
ユーザー とりゐとりゐ
提出日時 2021-11-17 01:53:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 110,572 KB
最終ジャッジ日時 2023-08-23 08:12:01
合計ジャッジ時間 8,800 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,224 KB
testcase_01 AC 69 ms
71,076 KB
testcase_02 AC 70 ms
70,956 KB
testcase_03 AC 71 ms
71,176 KB
testcase_04 AC 71 ms
71,356 KB
testcase_05 AC 69 ms
71,304 KB
testcase_06 AC 67 ms
70,944 KB
testcase_07 AC 71 ms
71,244 KB
testcase_08 AC 70 ms
71,336 KB
testcase_09 AC 70 ms
71,176 KB
testcase_10 AC 71 ms
71,176 KB
testcase_11 AC 77 ms
75,548 KB
testcase_12 AC 79 ms
76,100 KB
testcase_13 AC 80 ms
76,324 KB
testcase_14 AC 77 ms
76,300 KB
testcase_15 AC 89 ms
76,728 KB
testcase_16 AC 114 ms
81,452 KB
testcase_17 AC 142 ms
86,780 KB
testcase_18 AC 180 ms
94,896 KB
testcase_19 AC 195 ms
99,904 KB
testcase_20 AC 230 ms
110,280 KB
testcase_21 AC 229 ms
110,572 KB
testcase_22 AC 233 ms
110,392 KB
testcase_23 AC 229 ms
110,096 KB
testcase_24 AC 227 ms
109,900 KB
testcase_25 AC 223 ms
110,240 KB
testcase_26 AC 174 ms
109,552 KB
testcase_27 AC 175 ms
109,560 KB
testcase_28 AC 177 ms
109,276 KB
testcase_29 AC 180 ms
109,388 KB
testcase_30 AC 177 ms
109,576 KB
testcase_31 AC 226 ms
109,556 KB
testcase_32 AC 227 ms
109,588 KB
testcase_33 AC 225 ms
109,596 KB
testcase_34 AC 225 ms
109,832 KB
testcase_35 AC 226 ms
109,604 KB
testcase_36 AC 221 ms
109,516 KB
testcase_37 AC 190 ms
109,752 KB
testcase_38 AC 232 ms
109,708 KB
testcase_39 AC 219 ms
109,340 KB
testcase_40 AC 226 ms
109,580 KB
testcase_41 AC 72 ms
71,444 KB
testcase_42 AC 71 ms
71,416 KB
testcase_43 AC 70 ms
71,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod=10**9+7
dp=[[0]*(n+1) for i in range(n)]
for i in range(n):
  dp[i][0]=1
  if len(edge[i])==1 and i!=0:
    dp[i][1]=1
d=[(0,0,0)]
seen=[1]*n
size=[1]*n
while d:
  x,y,z=d.pop()
  if x==0:
    seen[y]=0
    for i in edge[y]:
      if seen[i]:
        d.append((1,i,y))
        d.append((0,i,y))
  else:
    dp_new=[0]*(n+1)
    for k1 in range(size[z]):
      for k2 in range(size[y]+1):
        dp_new[k1+k2]+=dp[z][k1]*dp[y][k2]
    size[z]+=size[y]
    for i in range(size[z]+1):
      dp[z][i]=dp_new[i]%mod
    dp[z][size[z]]=1

print(dp[0][k])
0