結果

問題 No.758 VVVVV
ユーザー りあんりあん
提出日時 2018-12-06 01:45:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 200,076 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 02:59:50
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 54 ms
5,376 KB
testcase_04 AC 24 ms
5,376 KB
testcase_05 AC 18 ms
5,376 KB
testcase_06 AC 17 ms
5,376 KB
testcase_07 AC 52 ms
5,376 KB
testcase_08 AC 28 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 20 ms
5,376 KB
testcase_11 AC 54 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 19 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 48 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 57 ms
5,376 KB
testcase_20 AC 17 ms
5,376 KB
testcase_21 AC 17 ms
5,376 KB
testcase_22 AC 58 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

long long powmod(long long a, long long b) {
    if (b == 0) return 1;
    long long t = powmod(a, b / 2);
    t = t * t % M;
    if (b & 1) t = t * a % M;
    return t;
}

long long inv(long long a) {
    return powmod(a, M - 2);
}

vector<long long> fact;

long long comb(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * inv(fact[k]) % M * inv(fact[n - k]) % M;
}

int main() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << "1\n";
        return 0;
    }
    fact = vector<long long>(n);
    fact[0] = 1;
    for (int i = 1; i < n; ++i) fact[i] = fact[i - 1] * i % M;

    vector<int> cnt(n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ++cnt[a];
        ++cnt[b];
    }
    int k = 0;
    for (int i = 1; i < n; ++i) if (cnt[i] == 1) ++k;

    cout << comb(n - 1, k) * comb(n - 1, k - 1) % M * inv(n - 1) % M << "\n";
    return 0;
}
0