結果
| 問題 |
No.758 VVVVV
|
| コンテスト | |
| ユーザー |
matsu7874
|
| 提出日時 | 2018-12-01 20:44:34 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 706 bytes |
| コンパイル時間 | 111 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 34,588 KB |
| 最終ジャッジ日時 | 2024-06-27 00:20:34 |
| 合計ジャッジ時間 | 4,367 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 3 TLE * 1 -- * 19 |
ソースコード
mod = 10**9 + 7
def combination(n, r):
res = 1
t = r - 1
while t >= 0:
res = res * (n - t) // (r - t)
t -= 1
return res
def main():
n = int(input())
assert 1 <= n <= 10**5
graph = [[] for _ in range(n)]
for _ in range(n - 1):
a, b = map(int, input().split())
assert 1 <= a <= n
assert 1 <= b <= n
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
if n == 1:
print(1)
exit()
leaf_cnt = len(list(filter(lambda x: len(x) == 1, graph[1:])))
print(combination(n - 1, leaf_cnt-1) *
combination(n - 2, leaf_cnt - 1) // leaf_cnt % mod)
if __name__ == "__main__":
main()
matsu7874