結果

問題 No.758 VVVVV
ユーザー matsu7874matsu7874
提出日時 2018-12-01 20:44:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 706 bytes
コンパイル時間 122 ms
コンパイル使用メモリ 10,864 KB
実行使用メモリ 29,360 KB
最終ジャッジ日時 2023-09-09 07:12:06
合計ジャッジ時間 4,555 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,184 KB
testcase_01 AC 16 ms
8,232 KB
testcase_02 AC 15 ms
7,800 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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