結果
問題 | No.1227 I hate ThREE |
ユーザー | chineristAC |
提出日時 | 2020-09-11 22:49:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,837 bytes |
コンパイル時間 | 224 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 104,320 KB |
最終ジャッジ日時 | 2024-06-08 11:43:24 |
合計ジャッジ時間 | 3,730 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,864 KB |
testcase_01 | AC | 43 ms
52,992 KB |
testcase_02 | AC | 39 ms
52,352 KB |
testcase_03 | AC | 70 ms
74,416 KB |
testcase_04 | AC | 67 ms
72,192 KB |
testcase_05 | WA | - |
testcase_06 | AC | 39 ms
52,480 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
ソースコード
import sys input = sys.stdin.readline sys.setrecursionlimit(2*10**5) 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(D): 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)