結果
問題 | No.1124 Earthquake Safety |
ユーザー | maspy |
提出日時 | 2020-07-22 22:49:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 929 ms / 3,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,944 KB |
実行使用メモリ | 191,288 KB |
最終ジャッジ日時 | 2024-06-22 23:48:26 |
合計ジャッジ時間 | 32,707 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
52,224 KB |
testcase_01 | AC | 38 ms
52,224 KB |
testcase_02 | AC | 37 ms
52,224 KB |
testcase_03 | AC | 41 ms
52,480 KB |
testcase_04 | AC | 41 ms
52,480 KB |
testcase_05 | AC | 42 ms
52,736 KB |
testcase_06 | AC | 59 ms
62,336 KB |
testcase_07 | AC | 101 ms
78,464 KB |
testcase_08 | AC | 261 ms
107,264 KB |
testcase_09 | AC | 750 ms
176,300 KB |
testcase_10 | AC | 482 ms
174,520 KB |
testcase_11 | AC | 37 ms
52,352 KB |
testcase_12 | AC | 38 ms
52,096 KB |
testcase_13 | AC | 41 ms
52,096 KB |
testcase_14 | AC | 799 ms
177,344 KB |
testcase_15 | AC | 823 ms
175,652 KB |
testcase_16 | AC | 850 ms
176,060 KB |
testcase_17 | AC | 815 ms
175,680 KB |
testcase_18 | AC | 807 ms
175,936 KB |
testcase_19 | AC | 830 ms
176,064 KB |
testcase_20 | AC | 813 ms
176,960 KB |
testcase_21 | AC | 827 ms
175,928 KB |
testcase_22 | AC | 887 ms
175,676 KB |
testcase_23 | AC | 807 ms
174,396 KB |
testcase_24 | AC | 802 ms
174,912 KB |
testcase_25 | AC | 770 ms
174,912 KB |
testcase_26 | AC | 764 ms
176,184 KB |
testcase_27 | AC | 810 ms
175,032 KB |
testcase_28 | AC | 813 ms
175,036 KB |
testcase_29 | AC | 847 ms
176,440 KB |
testcase_30 | AC | 779 ms
175,676 KB |
testcase_31 | AC | 929 ms
175,676 KB |
testcase_32 | AC | 925 ms
175,288 KB |
testcase_33 | AC | 877 ms
174,784 KB |
testcase_34 | AC | 763 ms
174,136 KB |
testcase_35 | AC | 675 ms
180,028 KB |
testcase_36 | AC | 766 ms
174,264 KB |
testcase_37 | AC | 651 ms
191,288 KB |
testcase_38 | AC | 674 ms
178,240 KB |
testcase_39 | AC | 652 ms
178,228 KB |
testcase_40 | AC | 635 ms
189,888 KB |
testcase_41 | AC | 641 ms
176,568 KB |
testcase_42 | AC | 580 ms
182,716 KB |
testcase_43 | AC | 643 ms
190,652 KB |
testcase_44 | AC | 644 ms
181,176 KB |
testcase_45 | AC | 697 ms
182,588 KB |
testcase_46 | AC | 617 ms
181,288 KB |
testcase_47 | AC | 656 ms
176,580 KB |
testcase_48 | AC | 610 ms
184,360 KB |
testcase_49 | AC | 476 ms
188,324 KB |
testcase_50 | AC | 39 ms
52,096 KB |
testcase_51 | AC | 38 ms
52,352 KB |
testcase_52 | AC | 37 ms
52,224 KB |
testcase_53 | AC | 39 ms
52,224 KB |
testcase_54 | AC | 39 ms
52,224 KB |
testcase_55 | AC | 37 ms
52,480 KB |
testcase_56 | AC | 38 ms
52,096 KB |
testcase_57 | AC | 39 ms
52,224 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 inv2 = pow(2, MOD - 2, MOD) inv4 = inv2**2 % MOD def dfs_order(G, root=1): parent = [0] * (N + 1) order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y in G[x]: if y == parent[x]: continue parent[y] = x stack.append(y) return parent, order N = int(readline()) m = map(int, read().split()) G = [[] for _ in range(N + 1)] for a, b in zip(m, m): G[a].append(b) G[b].append(a) root = 1 parent, order = dfs_order(G, root) mu1 = [0] * (N + 1) var1 = [0] * (N + 1) for v in order[::-1]: p = parent[v] mu1[v] += 1 mu1[v] %= MOD var1[v] %= MOD mu1[p] += inv2 * mu1[v] var1[p] += var1[v] * inv2 + mu1[v] * mu1[v] * inv4 mu2 = [0] * (N + 1) var2 = [0] * (N + 1) for v in order: mu2[v] = mu1[v] var2[v] = var1[v] if v == root: continue p = parent[v] mu = mu2[p] - mu1[v] * inv2 var = var2[p] - inv2 * var2[v] - mu1[v]**2 * inv4 mu2[v] += mu * inv2 var2[v] += mu * mu * inv4 + var * inv2 mu2[v] %= MOD var2[v] %= MOD ans = 0 for v in range(1, N+1): ans += mu2[v] ** 2 + var2[v] ans *= pow(2, N-1, MOD) print(ans % MOD)