結果

問題 No.1227 I hate ThREE
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-09-12 02:04:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,397 ms / 2,000 ms
コード長 1,663 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 86,952 KB
実行使用メモリ 191,060 KB
最終ジャッジ日時 2023-08-30 14:56:30
合計ジャッジ時間 25,584 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,636 KB
testcase_01 AC 79 ms
71,376 KB
testcase_02 AC 76 ms
71,224 KB
testcase_03 AC 256 ms
83,648 KB
testcase_04 AC 163 ms
79,532 KB
testcase_05 AC 156 ms
79,480 KB
testcase_06 AC 75 ms
71,520 KB
testcase_07 AC 75 ms
71,416 KB
testcase_08 AC 153 ms
81,044 KB
testcase_09 AC 142 ms
80,148 KB
testcase_10 AC 116 ms
78,964 KB
testcase_11 AC 840 ms
106,532 KB
testcase_12 AC 932 ms
109,568 KB
testcase_13 AC 108 ms
77,540 KB
testcase_14 AC 201 ms
83,628 KB
testcase_15 AC 216 ms
84,712 KB
testcase_16 AC 482 ms
98,000 KB
testcase_17 AC 263 ms
87,668 KB
testcase_18 AC 672 ms
104,288 KB
testcase_19 AC 511 ms
98,960 KB
testcase_20 AC 663 ms
108,048 KB
testcase_21 AC 99 ms
77,000 KB
testcase_22 AC 520 ms
100,544 KB
testcase_23 AC 1,278 ms
185,664 KB
testcase_24 AC 1,397 ms
167,628 KB
testcase_25 AC 1,340 ms
191,060 KB
testcase_26 AC 1,168 ms
121,740 KB
testcase_27 AC 1,259 ms
126,732 KB
testcase_28 AC 1,320 ms
127,376 KB
testcase_29 AC 1,239 ms
128,508 KB
testcase_30 AC 1,216 ms
124,120 KB
testcase_31 AC 1,110 ms
122,444 KB
testcase_32 AC 1,270 ms
126,212 KB
testcase_33 AC 1,105 ms
122,668 KB
testcase_34 AC 1,234 ms
126,524 KB
testcase_35 AC 1,076 ms
123,160 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