結果

問題 No.196 典型DP (1)
ユーザー titiatitia
提出日時 2022-06-20 02:15:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 79 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 40,448 KB
最終ジャッジ日時 2024-04-20 12:32:07
合計ジャッジ時間 41,686 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,880 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 28 ms
11,008 KB
testcase_05 AC 28 ms
10,880 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 28 ms
10,752 KB
testcase_08 AC 29 ms
10,880 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 29 ms
10,880 KB
testcase_11 AC 29 ms
11,008 KB
testcase_12 AC 31 ms
10,880 KB
testcase_13 AC 31 ms
10,880 KB
testcase_14 AC 32 ms
10,880 KB
testcase_15 AC 68 ms
11,136 KB
testcase_16 AC 173 ms
11,264 KB
testcase_17 AC 370 ms
11,520 KB
testcase_18 AC 691 ms
12,416 KB
testcase_19 AC 869 ms
12,544 KB
testcase_20 AC 1,178 ms
12,416 KB
testcase_21 AC 1,267 ms
12,544 KB
testcase_22 AC 1,194 ms
12,544 KB
testcase_23 AC 1,506 ms
40,448 KB
testcase_24 AC 1,478 ms
31,616 KB
testcase_25 AC 1,443 ms
28,928 KB
testcase_26 AC 1,580 ms
29,056 KB
testcase_27 AC 1,585 ms
29,184 KB
testcase_28 AC 1,585 ms
29,184 KB
testcase_29 AC 1,603 ms
29,056 KB
testcase_30 AC 1,546 ms
29,056 KB
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 AC 1,243 ms
11,776 KB
testcase_38 TLE -
testcase_39 AC 1,958 ms
11,648 KB
testcase_40 TLE -
testcase_41 AC 29 ms
10,880 KB
testcase_42 AC 30 ms
10,880 KB
testcase_43 AC 29 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int,input().split())
E=[[] for i in range(N)]

mod=10**9+7

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

ROOT=0
QUE=[ROOT] 
Parent=[-1]*N
Parent[ROOT]=N # ROOTの親を定めておく.
Child=[[] for i in range(N)]
TOP_SORT=[] # トポロジカルソート

while QUE: # トポロジカルソートと同時に親を見つける
    x=QUE.pop()
    TOP_SORT.append(x)
    for to in E[x]:
        if Parent[to]==-1:
            Parent[to]=x
            Child[x].append(to)
            QUE.append(to)

DP=[[] for i in range(N)]

for x in TOP_SORT[::-1]:
    if len(Child[x])==0:
        DP[x]=[1,1]
        continue

    NDP=[1]
    
    for to in Child[x]:
        XDP=[0]*(len(DP[to])+len(NDP)-1)
        for i in range(len(DP[to])):
            for j in range(len(NDP)):
                XDP[i+j]+=DP[to][i]*NDP[j]%mod
                XDP[i+j]%=mod
        NDP=XDP

    NDP.append(1)

    DP[x]=NDP

print(DP[0][K]%mod)
            
        
        

    
0