結果
問題 | No.1227 I hate ThREE |
ユーザー | WSKR |
提出日時 | 2020-09-22 00:16:40 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,450 bytes |
コンパイル時間 | 191 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 125,440 KB |
最終ジャッジ日時 | 2024-06-24 23:38:53 |
合計ジャッジ時間 | 5,463 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,656 KB |
testcase_01 | AC | 44 ms
54,528 KB |
testcase_02 | AC | 44 ms
54,528 KB |
testcase_03 | AC | 97 ms
77,988 KB |
testcase_04 | AC | 104 ms
78,064 KB |
testcase_05 | AC | 146 ms
79,744 KB |
testcase_06 | AC | 45 ms
54,528 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 | - |
ソースコード
#i hate three from collections import deque import sys sys.setrecursionlimit(10**7) mod = 10**9 + 7 def main(): N, C = map(int, input().split()) G = [[] for i in range(N+1)] for i in range(N-1): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) visited = [False for i in range(N+1)] depth = [0 for i in range(N+1)] child_cnt = [1 for i in range(N+1)] que = deque([]) def dfs(s_node): visited[s_node] = True for child in G[s_node]: if visited[child] == False: depth[child] = depth[s_node] + 1 dfs(child) for child in G[s_node]: if depth[child] > depth[s_node]: child_cnt[s_node] += child_cnt[child] que.append(s_node) dfs(1) if C > 8*N: dp = [[0 for i in range(6*N-5)] for i in range(N+1)] while que: node = que.popleft() for i in range(3*N-4): has_child = False v = 1 for child in G[node]: if depth[child] > depth[node]: tmp_u = 0 has_child = True if i >= 3: tmp_u += dp[child][i-3] if i+3 <= 3*N-5: tmp_u += dp[child][i+3] elif i+3 > 3*N-5: tmp_u += pow(2, child_cnt[child]-1, mod) v *= tmp_u v %= mod dp[node][i] = v if has_child == False: dp[node][i] = 1 for i in range(3*N-3, 6*N-5): has_child = False v = 1 for child in G[node]: if depth[child] > depth[node]: tmp_u = 0 has_child = True if i+3 <= 6*N-6: tmp_u += dp[child][i+3] if i-3 >= 3*N-3: tmp_u += dp[child][i-3] else: tmp_u += pow(2, child_cnt[child]-1, mod) v *= tmp_u v %= mod dp[node][i] = v if has_child == False: dp[node][i] = 1 ans = sum(dp[1][i] for i in range(3*N-4)) + sum(dp[1][i] for i in range(3*N-3, 6*N-5)) + (C-6*N + 6)*pow(2, N-1, mod) print(ans % mod) return elif C <= 8*N: dp = [[0 for i in range(C+1)] for j in range(N+1)] while que: node = que.popleft() for i in range(1, C+1): has_child = False v = 1 for child in G[node]: if depth[child] > depth[node]: has_child = True tmp_u = 0 if 1 <= i-3 <= C: tmp_u += dp[child][i-3] if 1 <= i+3 <= C: tmp_u += dp[child][i+3] v *= (tmp_u) dp[node][i] = v % mod if has_child == False: dp[node][i] = 1 ans = sum(dp[1][i] for i in range(1, C+1)) % mod print(ans) return if __name__ == "__main__": main()