結果
問題 | No.1227 I hate ThREE |
ユーザー | mkawa2 |
提出日時 | 2021-07-25 19:10:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 385 ms / 2,000 ms |
コード長 | 1,438 bytes |
コンパイル時間 | 1,878 ms |
コンパイル使用メモリ | 81,664 KB |
実行使用メモリ | 122,880 KB |
最終ジャッジ日時 | 2024-07-21 03:39:08 |
合計ジャッジ時間 | 10,023 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,096 KB |
testcase_01 | AC | 34 ms
51,968 KB |
testcase_02 | AC | 33 ms
51,840 KB |
testcase_03 | AC | 75 ms
72,960 KB |
testcase_04 | AC | 74 ms
73,088 KB |
testcase_05 | AC | 81 ms
72,576 KB |
testcase_06 | AC | 34 ms
51,968 KB |
testcase_07 | AC | 34 ms
52,352 KB |
testcase_08 | AC | 81 ms
71,168 KB |
testcase_09 | AC | 78 ms
69,760 KB |
testcase_10 | AC | 69 ms
67,456 KB |
testcase_11 | AC | 335 ms
111,872 KB |
testcase_12 | AC | 385 ms
111,616 KB |
testcase_13 | AC | 57 ms
64,512 KB |
testcase_14 | AC | 92 ms
79,616 KB |
testcase_15 | AC | 112 ms
82,432 KB |
testcase_16 | AC | 175 ms
93,184 KB |
testcase_17 | AC | 125 ms
85,248 KB |
testcase_18 | AC | 229 ms
100,608 KB |
testcase_19 | AC | 195 ms
94,464 KB |
testcase_20 | AC | 258 ms
103,168 KB |
testcase_21 | AC | 49 ms
62,080 KB |
testcase_22 | AC | 193 ms
95,488 KB |
testcase_23 | AC | 355 ms
121,216 KB |
testcase_24 | AC | 351 ms
122,880 KB |
testcase_25 | AC | 365 ms
122,880 KB |
testcase_26 | AC | 331 ms
118,528 KB |
testcase_27 | AC | 363 ms
121,344 KB |
testcase_28 | AC | 372 ms
122,752 KB |
testcase_29 | AC | 366 ms
122,496 KB |
testcase_30 | AC | 357 ms
119,680 KB |
testcase_31 | AC | 346 ms
119,552 KB |
testcase_32 | AC | 366 ms
122,240 KB |
testcase_33 | AC | 356 ms
118,912 KB |
testcase_34 | AC | 357 ms
120,960 KB |
testcase_35 | AC | 342 ms
118,784 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = 10**16 # md = 998244353 md = 10**9+7 n, c = LI() to = [[] for _ in range(n)] for _ in range(n-1): u, v = LI1() to[u].append(v) to[v].append(u) maxu = min(3*n-3, c) maxj = min(6*n-6, c) dp = [[1]*(maxj+1) for _ in range(n)] dfsorder = [] parent = [-1]*n stack = [0] while stack: u = stack.pop() dfsorder.append(u) for v in to[u]: if v == parent[u]: continue parent[v] = u stack.append(v) # print(dfsorder) for u in dfsorder[::-1]: for j in range(1, maxj+1): for v in to[u]: if v == parent[u]: continue cur = 0 if j+3 <= maxj: cur += dp[v][j+3] if j-3 > 0: cur += dp[v][j-3] dp[u][j] = dp[u][j]*cur%md ans = sum(dp[0][1:maxu+1])%md suf = min(c-maxu, maxu) ans += sum(dp[0][1:1+suf]) ans += (c-maxu-suf)*pow(2, n-1, md)%md print(ans%md)