結果
問題 | No.827 総神童数 |
ユーザー | 双六 |
提出日時 | 2020-08-04 04:02:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 472 ms / 2,000 ms |
コード長 | 1,580 bytes |
コンパイル時間 | 1,087 ms |
コンパイル使用メモリ | 86,932 KB |
実行使用メモリ | 124,528 KB |
最終ジャッジ日時 | 2023-10-11 23:30:02 |
合計ジャッジ時間 | 14,331 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
71,720 KB |
testcase_01 | AC | 94 ms
71,420 KB |
testcase_02 | AC | 96 ms
71,460 KB |
testcase_03 | AC | 100 ms
71,336 KB |
testcase_04 | AC | 100 ms
71,420 KB |
testcase_05 | AC | 97 ms
71,572 KB |
testcase_06 | AC | 97 ms
71,596 KB |
testcase_07 | AC | 95 ms
71,740 KB |
testcase_08 | AC | 94 ms
71,780 KB |
testcase_09 | AC | 323 ms
122,624 KB |
testcase_10 | AC | 175 ms
91,512 KB |
testcase_11 | AC | 121 ms
78,112 KB |
testcase_12 | AC | 142 ms
83,340 KB |
testcase_13 | AC | 263 ms
112,260 KB |
testcase_14 | AC | 124 ms
78,132 KB |
testcase_15 | AC | 167 ms
90,680 KB |
testcase_16 | AC | 275 ms
111,144 KB |
testcase_17 | AC | 309 ms
121,952 KB |
testcase_18 | AC | 193 ms
95,924 KB |
testcase_19 | AC | 472 ms
124,528 KB |
testcase_20 | AC | 363 ms
108,156 KB |
testcase_21 | AC | 291 ms
100,676 KB |
testcase_22 | AC | 376 ms
113,352 KB |
testcase_23 | AC | 118 ms
78,028 KB |
testcase_24 | AC | 433 ms
117,056 KB |
testcase_25 | AC | 341 ms
105,968 KB |
testcase_26 | AC | 444 ms
117,260 KB |
testcase_27 | AC | 314 ms
104,108 KB |
testcase_28 | AC | 304 ms
102,036 KB |
testcase_29 | AC | 272 ms
98,768 KB |
testcase_30 | AC | 164 ms
83,360 KB |
testcase_31 | AC | 230 ms
92,448 KB |
testcase_32 | AC | 225 ms
92,496 KB |
testcase_33 | AC | 455 ms
121,936 KB |
testcase_34 | AC | 429 ms
118,180 KB |
testcase_35 | AC | 230 ms
93,376 KB |
testcase_36 | AC | 283 ms
99,684 KB |
testcase_37 | AC | 348 ms
107,108 KB |
testcase_38 | AC | 462 ms
118,332 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict from collections import deque con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) class BFS(object): def __init__(self, graph, s, N): self.g = graph.graph self.Q = deque(); self.Q.append(s) self.dist = [INF] * N; self.dist[s] = 0 while self.Q: v = self.Q.popleft() for i in self.g[v]: if self.dist[i] == INF: self.dist[i] = self.dist[v] + 1 self.Q.append(i) class Combination(object): def __init__(self, N, con): self.fac = [0] * (N + 1) self.inv = [0] * (N + 1) self.finv = [0] * (N + 1) self.fac[0], self.fac[1] = 1, 1 self.inv[1] = 1 self.finv[0], self.finv[1] = 1, 1 # 前計算 for i in range(2, N + 1): self.fac[i] = self.fac[i - 1] * i % con self.inv[i] = self.inv[con % i] * (con - (con // i)) % con self.finv[i] = self.finv[i - 1] * self.inv[i] % con def com(self, N, k): return (self.fac[N] * self.finv[k] * self.finv[N - k]) % con #処理内容 def main(): N = int(input()) G = Graph() for i in range(N - 1): a, b = getlist() a -= 1; b -= 1 G.add_edge(a, b) G.add_edge(b, a) BF = BFS(G, 0, N) dist = BF.dist C = Combination(N, con) ans = 0 for i in range(N): ans += C.fac[N] * C.inv[dist[i] + 1] ans %= con print(ans) if __name__ == '__main__': main()