結果

問題 No.1227 I hate ThREE
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-09-12 02:04:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,309 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 188,764 KB
最終ジャッジ日時 2024-06-10 14:52:44
合計ジャッジ時間 21,125 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
51,840 KB
testcase_01 AC 35 ms
52,480 KB
testcase_02 AC 38 ms
52,480 KB
testcase_03 AC 202 ms
81,920 KB
testcase_04 AC 127 ms
77,952 KB
testcase_05 AC 123 ms
77,952 KB
testcase_06 AC 38 ms
52,352 KB
testcase_07 AC 35 ms
52,224 KB
testcase_08 AC 112 ms
79,552 KB
testcase_09 AC 105 ms
78,712 KB
testcase_10 AC 80 ms
77,236 KB
testcase_11 AC 734 ms
105,480 KB
testcase_12 AC 829 ms
108,288 KB
testcase_13 AC 76 ms
76,544 KB
testcase_14 AC 151 ms
80,564 KB
testcase_15 AC 177 ms
83,020 KB
testcase_16 AC 382 ms
97,348 KB
testcase_17 AC 216 ms
86,400 KB
testcase_18 AC 543 ms
102,728 KB
testcase_19 AC 417 ms
98,048 KB
testcase_20 AC 550 ms
104,444 KB
testcase_21 AC 63 ms
71,296 KB
testcase_22 AC 430 ms
98,608 KB
testcase_23 AC 1,154 ms
181,008 KB
testcase_24 AC 1,309 ms
165,504 KB
testcase_25 AC 1,241 ms
188,764 KB
testcase_26 AC 1,056 ms
120,448 KB
testcase_27 AC 1,092 ms
125,240 KB
testcase_28 AC 1,143 ms
125,312 KB
testcase_29 AC 1,094 ms
125,276 KB
testcase_30 AC 1,040 ms
121,296 KB
testcase_31 AC 980 ms
121,216 KB
testcase_32 AC 1,107 ms
124,928 KB
testcase_33 AC 973 ms
121,252 KB
testcase_34 AC 1,082 ms
125,676 KB
testcase_35 AC 935 ms
120,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

mod で場合分け
→使える数字の数が変わる

使える数字がX種類の時
数字の付け方を
2 <= X <= N の範囲で求めればいい?

1<=p<=Cの制約の影響を受けない範囲は省いてdp



"""

from sys import stdin
import sys
sys.setrecursionlimit(20000)

def dfs(v,p,num):

    #if memo[v][num] != None:
    #    return memo[v][num]

    ret = 1
    for nex in lis[v]:
        tmp = 0
        if nex != p:
            if num+1 < c:
                if memo[nex][num+1] == None:
                    tmp += dfs(nex,v,num+1)
                else:
                    tmp += memo[nex][num+1]
            if num-1 >= 0:
                if memo[nex][num-1] == None:
                    tmp += dfs(nex,v,num-1)
                else:
                    tmp += memo[nex][num-1]
            ret *= tmp
            ret %= mod

    memo[v][num] = ret
    return ret
                

N,C = map(int,stdin.readline().split())
lis = [ [] for i in range(N) ]

for i in range(N-1):

    a,b = map(int,stdin.readline().split())
    a -= 1
    b -= 1
    lis[a].append(b)
    lis[b].append(a)

#mod 0
mod = 10**9+7
ans = 0


clis = [C//3,C//3+1]
anss = []
for c in clis:
    ans = 0
    if c < 4*N:
        memo = [ [None] * c for i in range(N) ]
        for i in range(c):
            ans += dfs(0,0,i)
    else:
        memo = [ [None] * (2*N) for i in range(N) ]
        for i in range(N):
            ans += dfs(0,0,i) * 2
        ans += pow(2,N-1,mod) * (c-2*N)
    anss.append(ans)

cl2 = [ C//3 , (C+2)//3 , (C+1)//3 ]
aaa = 0
for i in cl2:
    for j in range(2):
        if clis[j] == i:
            aaa += anss[j]
print (aaa % mod)
0