結果

問題 No.827 総神童数
ユーザー silversmithsilversmith
提出日時 2019-05-14 00:05:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 867 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 58,916 KB
最終ジャッジ日時 2023-09-22 20:54:11
合計ジャッジ時間 4,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,196 KB
testcase_01 AC 16 ms
7,872 KB
testcase_02 AC 17 ms
8,272 KB
testcase_03 AC 15 ms
8,240 KB
testcase_04 AC 15 ms
8,104 KB
testcase_05 AC 15 ms
8,088 KB
testcase_06 AC 15 ms
8,120 KB
testcase_07 AC 15 ms
8,140 KB
testcase_08 AC 15 ms
8,120 KB
testcase_09 TLE -
testcase_10 AC 980 ms
25,984 KB
testcase_11 AC 60 ms
9,168 KB
testcase_12 AC 438 ms
15,836 KB
testcase_13 TLE -
testcase_14 AC 105 ms
9,808 KB
testcase_15 AC 900 ms
24,572 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 1,170 ms
29,592 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 1,510 ms
32,776 KB
testcase_22 TLE -
testcase_23 AC 32 ms
8,340 KB
testcase_24 TLE -
testcase_25 AC 1,900 ms
38,080 KB
testcase_26 TLE -
testcase_27 AC 1,674 ms
34,472 KB
testcase_28 AC 1,634 ms
34,176 KB
testcase_29 AC 1,325 ms
29,768 KB
testcase_30 AC 403 ms
14,500 KB
testcase_31 AC 1,021 ms
24,548 KB
testcase_32 AC 983 ms
23,688 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 1,032 ms
24,520 KB
testcase_36 AC 1,480 ms
32,368 KB
testcase_37 AC 1,884 ms
37,988 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):
    u, v = map(int, input().split())
    edge[u].append(v)
    edge[v].append(u)

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