結果

問題 No.827 総神童数
ユーザー kurimupykurimupy
提出日時 2020-06-15 15:04:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,796 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 79,724 KB
最終ジャッジ日時 2023-09-16 10:19:02
合計ジャッジ時間 30,692 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,968 KB
testcase_01 AC 14 ms
7,868 KB
testcase_02 AC 16 ms
7,800 KB
testcase_03 AC 15 ms
7,868 KB
testcase_04 AC 15 ms
7,784 KB
testcase_05 AC 14 ms
7,936 KB
testcase_06 AC 14 ms
7,788 KB
testcase_07 AC 15 ms
7,872 KB
testcase_08 AC 15 ms
7,836 KB
testcase_09 AC 1,796 ms
79,724 KB
testcase_10 AC 567 ms
30,716 KB
testcase_11 AC 40 ms
9,416 KB
testcase_12 AC 252 ms
19,460 KB
testcase_13 AC 1,390 ms
67,240 KB
testcase_14 AC 66 ms
10,524 KB
testcase_15 AC 517 ms
31,672 KB
testcase_16 AC 1,503 ms
54,288 KB
testcase_17 AC 1,672 ms
65,264 KB
testcase_18 AC 671 ms
37,292 KB
testcase_19 AC 1,637 ms
45,688 KB
testcase_20 AC 1,170 ms
34,244 KB
testcase_21 AC 851 ms
27,220 KB
testcase_22 AC 1,297 ms
38,164 KB
testcase_23 AC 25 ms
8,416 KB
testcase_24 AC 1,425 ms
39,468 KB
testcase_25 AC 1,061 ms
32,072 KB
testcase_26 AC 1,430 ms
39,664 KB
testcase_27 AC 951 ms
29,296 KB
testcase_28 AC 925 ms
29,092 KB
testcase_29 AC 737 ms
25,056 KB
testcase_30 AC 225 ms
13,424 KB
testcase_31 AC 565 ms
21,264 KB
testcase_32 AC 544 ms
20,920 KB
testcase_33 AC 1,587 ms
42,812 KB
testcase_34 AC 1,448 ms
40,668 KB
testcase_35 AC 580 ms
21,512 KB
testcase_36 AC 822 ms
26,984 KB
testcase_37 AC 1,086 ms
32,120 KB
testcase_38 AC 1,563 ms
42,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
N = int(input())
graph = [[] for i in range(N+1)]
for i in range(N-1):
    u, v = map(int, input().split())
    graph[u].append(v)
    graph[v].append(u)
visited = [False for i in range(N+1)]
distance = [1 for i in range(N+1)]


def dfs(S):
    visited[S] = True
    for node in graph[S]:
        if visited[node] == False:
            visited[node] = True
            distance[node] = distance[S]+1
            dfs(node)


dfs(1)
mod = 10**9+7
power = 1
for i in range(1, N+1):
    power *= i
    power %= mod


def rev(X, mod):
    return pow(X, mod-2, mod)


ans = 0
for i in range(1, N+1):
    ans += power*rev(distance[i],mod) % mod
print(ans % mod)
0