結果
問題 | No.827 総神童数 |
ユーザー | maspy |
提出日時 | 2020-02-29 00:29:08 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,290 ms / 2,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 97,552 KB |
最終ジャッジ日時 | 2024-10-13 19:36:09 |
合計ジャッジ時間 | 36,358 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 514 ms
57,868 KB |
testcase_01 | AC | 519 ms
58,372 KB |
testcase_02 | AC | 516 ms
58,112 KB |
testcase_03 | AC | 518 ms
58,376 KB |
testcase_04 | AC | 533 ms
58,372 KB |
testcase_05 | AC | 532 ms
57,612 KB |
testcase_06 | AC | 528 ms
57,612 KB |
testcase_07 | AC | 518 ms
58,124 KB |
testcase_08 | AC | 530 ms
57,728 KB |
testcase_09 | AC | 1,170 ms
97,552 KB |
testcase_10 | AC | 704 ms
70,604 KB |
testcase_11 | AC | 540 ms
58,760 KB |
testcase_12 | AC | 602 ms
63,920 KB |
testcase_13 | AC | 1,016 ms
89,096 KB |
testcase_14 | AC | 579 ms
59,160 KB |
testcase_15 | AC | 693 ms
69,888 KB |
testcase_16 | AC | 1,023 ms
89,532 KB |
testcase_17 | AC | 1,139 ms
95,908 KB |
testcase_18 | AC | 771 ms
73,312 KB |
testcase_19 | AC | 1,290 ms
96,700 KB |
testcase_20 | AC | 967 ms
81,660 KB |
testcase_21 | AC | 830 ms
75,904 KB |
testcase_22 | AC | 1,058 ms
85,428 KB |
testcase_23 | AC | 529 ms
57,744 KB |
testcase_24 | AC | 1,098 ms
89,392 KB |
testcase_25 | AC | 916 ms
80,044 KB |
testcase_26 | AC | 1,096 ms
88,988 KB |
testcase_27 | AC | 872 ms
77,528 KB |
testcase_28 | AC | 942 ms
77,120 KB |
testcase_29 | AC | 797 ms
71,960 KB |
testcase_30 | AC | 597 ms
62,244 KB |
testcase_31 | AC | 725 ms
68,848 KB |
testcase_32 | AC | 722 ms
68,392 KB |
testcase_33 | AC | 1,218 ms
94,812 KB |
testcase_34 | AC | 1,158 ms
89,736 KB |
testcase_35 | AC | 734 ms
69,664 KB |
testcase_36 | AC | 834 ms
75,464 KB |
testcase_37 | AC | 946 ms
79,744 KB |
testcase_38 | AC | 1,223 ms
93,660 KB |
ソースコード
#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% import numpy as np MOD = 10**9 + 7 # %% N = int(readline()) m = map(int, read().split()) UV = zip(m, m) # %% G = [[] for _ in range(N + 1)] for u, v in UV: G[u].append(v) G[v].append(u) # %% def cumprod(A, MOD=MOD): L = len(A) Lsq = int(L**.5 + 1) A = np.resize(A, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): A[:, n] *= A[:, n - 1] A[:, n] %= MOD for n in range(1, Lsq): A[n] *= A[n - 1, -1] A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD=MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact, fact_inv # %% fact, fact_inv = make_fact(2 * 10**5 + 10) inv = np.zeros_like(fact) inv[1:] = fact[:-1] * fact_inv[1:] % MOD inv = inv.tolist() # %% depth = [0] * (N + 1) depth[1] = 1 stack = [1] while stack: v = stack.pop() for w in G[v]: if depth[w]: continue depth[w] = depth[v] + 1 stack.append(w) # %% x = 0 for d in depth[1:]: x += inv[d] x %= MOD x *= fact[N] x %= MOD print(x)