結果

問題 No.827 総神童数
ユーザー silversmithsilversmith
提出日時 2019-05-13 23:48:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 834 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 11,040 KB
実行使用メモリ 63,408 KB
最終ジャッジ日時 2023-09-22 20:30:12
合計ジャッジ時間 6,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,732 KB
testcase_01 AC 16 ms
8,328 KB
testcase_02 AC 16 ms
8,176 KB
testcase_03 AC 16 ms
8,244 KB
testcase_04 AC 16 ms
8,176 KB
testcase_05 AC 16 ms
8,196 KB
testcase_06 AC 15 ms
8,272 KB
testcase_07 AC 16 ms
8,284 KB
testcase_08 AC 15 ms
8,300 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
prime = 10**9 + 7
f = [1] * (N + 1)
for i in range(1, N + 1):
    f[i] = i * f[i-1] % prime
f[0] =f[N]

def inv(x,prime):
    _x = x
    inv = 1
    k = prime -2
    while k > 0:
        if k % 2 == 1:
            inv = (inv * _x) % prime
        _x = (_x * _x) % prime   
        k = int(k /2)
    return inv

for i in range(1,N+1):
    f[i] = f[0] * inv(i, prime) % prime

a = [0] * (N + 1)
flag = [False] * (N+1)

edge = [[] for _ in range(N + 1)]
for _ in range(N-1):
    e = list(map(int, input().split()))
    edge[e[0]].append(e[1])
    edge[e[1]].append(e[0])

q = [1]
a[1] = 1
while len(q) > 0:
    v = q.pop()
    flag[v] = True
    for child in edge[v]:
        if flag[child] == False:
            q.append(child)
            a[child] = a[v] + 1

print(int(sum([f[a[i]] for i in range(1, N+1)])) % prime)
0