結果
問題 | No.1124 Earthquake Safety |
ユーザー | maspy |
提出日時 | 2020-07-22 22:46:53 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,300 ms / 3,000 ms |
コード長 | 1,349 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 112,156 KB |
最終ジャッジ日時 | 2024-06-22 23:46:11 |
合計ジャッジ時間 | 82,761 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
10,880 KB |
testcase_01 | AC | 26 ms
10,752 KB |
testcase_02 | AC | 25 ms
10,880 KB |
testcase_03 | AC | 26 ms
10,880 KB |
testcase_04 | AC | 25 ms
10,880 KB |
testcase_05 | AC | 24 ms
11,008 KB |
testcase_06 | AC | 28 ms
11,264 KB |
testcase_07 | AC | 71 ms
13,952 KB |
testcase_08 | AC | 610 ms
41,356 KB |
testcase_09 | AC | 2,096 ms
102,736 KB |
testcase_10 | AC | 1,590 ms
112,156 KB |
testcase_11 | AC | 26 ms
10,880 KB |
testcase_12 | AC | 26 ms
10,880 KB |
testcase_13 | AC | 25 ms
10,752 KB |
testcase_14 | AC | 2,223 ms
102,928 KB |
testcase_15 | AC | 2,195 ms
102,840 KB |
testcase_16 | AC | 2,254 ms
102,624 KB |
testcase_17 | AC | 2,187 ms
102,740 KB |
testcase_18 | AC | 2,177 ms
102,700 KB |
testcase_19 | AC | 2,162 ms
102,792 KB |
testcase_20 | AC | 2,242 ms
102,752 KB |
testcase_21 | AC | 2,205 ms
102,832 KB |
testcase_22 | AC | 2,243 ms
102,612 KB |
testcase_23 | AC | 2,272 ms
107,040 KB |
testcase_24 | AC | 2,300 ms
106,548 KB |
testcase_25 | AC | 2,227 ms
104,912 KB |
testcase_26 | AC | 2,170 ms
104,944 KB |
testcase_27 | AC | 2,098 ms
105,076 KB |
testcase_28 | AC | 2,126 ms
105,456 KB |
testcase_29 | AC | 2,137 ms
106,712 KB |
testcase_30 | AC | 2,206 ms
106,788 KB |
testcase_31 | AC | 2,155 ms
108,284 KB |
testcase_32 | AC | 2,106 ms
108,424 KB |
testcase_33 | AC | 2,112 ms
112,088 KB |
testcase_34 | AC | 2,092 ms
112,148 KB |
testcase_35 | AC | 2,089 ms
97,092 KB |
testcase_36 | AC | 2,110 ms
99,488 KB |
testcase_37 | AC | 1,966 ms
97,224 KB |
testcase_38 | AC | 1,988 ms
98,936 KB |
testcase_39 | AC | 1,942 ms
97,420 KB |
testcase_40 | AC | 2,040 ms
97,740 KB |
testcase_41 | AC | 2,159 ms
97,900 KB |
testcase_42 | AC | 1,826 ms
97,628 KB |
testcase_43 | AC | 1,793 ms
98,016 KB |
testcase_44 | AC | 1,800 ms
95,916 KB |
testcase_45 | AC | 1,810 ms
95,880 KB |
testcase_46 | AC | 1,843 ms
97,620 KB |
testcase_47 | AC | 1,853 ms
95,720 KB |
testcase_48 | AC | 1,830 ms
96,436 KB |
testcase_49 | AC | 1,892 ms
95,688 KB |
testcase_50 | AC | 26 ms
10,880 KB |
testcase_51 | AC | 29 ms
10,880 KB |
testcase_52 | AC | 25 ms
10,752 KB |
testcase_53 | AC | 25 ms
11,008 KB |
testcase_54 | AC | 25 ms
10,752 KB |
testcase_55 | AC | 25 ms
10,752 KB |
testcase_56 | AC | 25 ms
10,752 KB |
testcase_57 | AC | 24 ms
10,880 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)