結果

問題 No.758 VVVVV
コンテスト
ユーザー matsu7874
提出日時 2018-12-01 20:44:34
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,760 ms / 2,000 ms
コード長 706 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 646 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 31,964 KB
最終ジャッジ日時 2026-03-14 00:25:50
合計ジャッジ時間 16,047 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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()
0