結果
問題 | No.1227 I hate ThREE |
ユーザー | chineristAC |
提出日時 | 2020-09-11 22:48:13 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,805 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 93,696 KB |
最終ジャッジ日時 | 2024-06-08 11:40:53 |
合計ジャッジ時間 | 4,170 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,480 KB |
testcase_01 | AC | 37 ms
52,480 KB |
testcase_02 | AC | 36 ms
52,224 KB |
testcase_03 | AC | 89 ms
73,984 KB |
testcase_04 | AC | 75 ms
71,936 KB |
testcase_05 | RE | - |
testcase_06 | AC | 37 ms
52,480 KB |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
ソースコード
import sys input = sys.stdin.readline mod = 10**9+7 N,C = map(int,input().split()) edge = [[] for i in range(N)] for i in range(N-1): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) depth = [-1 for i in range(N)] parent = [-1 for i in range(N)] size = [1 for i in range(N)] depth[0] = 0 def dfs(v,pv): for nv in edge[v]: if nv!=pv: parent[nv] = v depth[nv] = depth[v] + 1 dfs(nv,v) size[v] += size[nv] dfs(0,-1) D = max(depth) def solve(M): if M<=2*D+1: dp = [[1 for i in range(M)] for j in range(N)] def dp_dfs(v,pv): for nv in edge[v]: if nv!=pv: dp_dfs(nv,v) for i in range(M): tmp = 0 if i!=0: tmp += dp[nv][i-1] if i!=M-1: tmp += dp[nv][i+1] tmp %= mod dp[v][i] *= tmp dp[v][i] %= mod dp_dfs(0,-1) res = 0 for i in range(M): res += dp[0][i] res %= mod return res else: dp_low = [[1 for i in range(D+1)] for j in range(N)] dp_high = [[1 for i in range(D+1)] for j in range(N)] def dp_dfs(v,pv): for nv in edge[v]: if nv!=pv: dp_dfs(nv,v) for i in range(M): tmp = 0 if i!=0: tmp += dp_low[nv][i-1] if i!=D: tmp += dp_low[nv][i+1] else: tmp += pow(2,size[nv],mod) tmp %= mod dp_low[v][i] *= tmp dp_low[v][i] %= mod tmp = 0 if i!=0: tmp += dp_high[nv][i-1] if i!=D: tmp += dp_high[nv][i+1] else: tmp += pow(2,size[nv],mod) tmp %= mod dp_low[v][i] *= tmp dp_low[v][i] %= mod dp_dfs(0,-1) res = 0 for i in range(D+1): res += dp_low[0][i] res %= mod res += dp_high[0][i] res %= mod tmp = pow(2,N,mod) * (M-2*D-2) %mod res += tmp res %= mod return res ans = 0 c = C//3 if C%3==1: ans += solve(c+1) + 2*solve(c) ans %= mod elif C%3==2: ans += 2*solve(c+1) + solve(c) ans %= mod else: ans = 3*solve(c) ans %= mod print(ans)