結果
問題 | No.1227 I hate ThREE |
ユーザー | iby |
提出日時 | 2020-11-29 00:48:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 548 ms / 2,000 ms |
コード長 | 3,466 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,100 KB |
実行使用メモリ | 124,712 KB |
最終ジャッジ日時 | 2024-09-13 01:43:07 |
合計ジャッジ時間 | 11,523 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
54,716 KB |
testcase_01 | AC | 42 ms
54,916 KB |
testcase_02 | AC | 42 ms
54,520 KB |
testcase_03 | AC | 98 ms
78,012 KB |
testcase_04 | AC | 99 ms
77,860 KB |
testcase_05 | AC | 104 ms
79,748 KB |
testcase_06 | AC | 43 ms
54,812 KB |
testcase_07 | AC | 43 ms
55,692 KB |
testcase_08 | AC | 129 ms
82,116 KB |
testcase_09 | AC | 116 ms
80,996 KB |
testcase_10 | AC | 100 ms
79,504 KB |
testcase_11 | AC | 482 ms
119,668 KB |
testcase_12 | AC | 537 ms
124,020 KB |
testcase_13 | AC | 76 ms
76,872 KB |
testcase_14 | AC | 118 ms
80,436 KB |
testcase_15 | AC | 137 ms
83,304 KB |
testcase_16 | AC | 237 ms
94,244 KB |
testcase_17 | AC | 167 ms
86,860 KB |
testcase_18 | AC | 290 ms
101,776 KB |
testcase_19 | AC | 242 ms
95,680 KB |
testcase_20 | AC | 312 ms
104,344 KB |
testcase_21 | AC | 63 ms
69,944 KB |
testcase_22 | AC | 249 ms
97,032 KB |
testcase_23 | AC | 524 ms
123,088 KB |
testcase_24 | AC | 548 ms
124,260 KB |
testcase_25 | AC | 542 ms
124,712 KB |
testcase_26 | AC | 429 ms
120,020 KB |
testcase_27 | AC | 470 ms
122,588 KB |
testcase_28 | AC | 487 ms
123,916 KB |
testcase_29 | AC | 466 ms
123,676 KB |
testcase_30 | AC | 446 ms
120,960 KB |
testcase_31 | AC | 454 ms
120,856 KB |
testcase_32 | AC | 482 ms
123,608 KB |
testcase_33 | AC | 441 ms
120,484 KB |
testcase_34 | AC | 445 ms
122,084 KB |
testcase_35 | AC | 438 ms
120,092 KB |
ソースコード
#skip problem -> from collections import deque 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 > 9*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-3): 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-4: tmp_u += dp[child][i+3] elif i+3 > 3*N-4: 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-2, 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-2: 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-3)) + sum(dp[1][i] for i in range(3*N-2, 6*N-5)) + (C-6*N + 6)*pow(2, N-1, mod) print(ans % mod) return elif C <= 9*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) v %= mod 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()