結果

問題 No.827 総神童数
ユーザー silversmithsilversmith
提出日時 2019-05-13 23:59:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 882 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 11,068 KB
実行使用メモリ 58,896 KB
最終ジャッジ日時 2023-09-22 20:44:02
合計ジャッジ時間 52,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,300 KB
testcase_01 AC 15 ms
7,724 KB
testcase_02 AC 16 ms
7,748 KB
testcase_03 AC 16 ms
7,824 KB
testcase_04 AC 15 ms
7,900 KB
testcase_05 AC 15 ms
7,868 KB
testcase_06 AC 15 ms
7,748 KB
testcase_07 AC 15 ms
8,236 KB
testcase_08 AC 15 ms
7,824 KB
testcase_09 TLE -
testcase_10 AC 1,017 ms
26,020 KB
testcase_11 AC 61 ms
8,968 KB
testcase_12 AC 444 ms
15,856 KB
testcase_13 TLE -
testcase_14 AC 108 ms
9,752 KB
testcase_15 AC 932 ms
24,492 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 1,203 ms
29,408 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 1,542 ms
32,648 KB
testcase_22 TLE -
testcase_23 AC 33 ms
8,524 KB
testcase_24 TLE -
testcase_25 AC 1,964 ms
38,044 KB
testcase_26 TLE -
testcase_27 AC 1,714 ms
34,612 KB
testcase_28 AC 1,711 ms
34,028 KB
testcase_29 AC 1,374 ms
29,740 KB
testcase_30 AC 417 ms
14,332 KB
testcase_31 AC 1,057 ms
24,576 KB
testcase_32 AC 1,006 ms
23,784 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 1,065 ms
24,564 KB
testcase_36 AC 1,516 ms
32,320 KB
testcase_37 AC 1,953 ms
37,952 KB
testcase_38 TLE -
権限があれば一括ダウンロードができます

ソースコード

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
f = [f[0] * inv(i,prime) for i in range(N+1)]

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