結果

問題 No.758 VVVVV
ユーザー りあんりあん
提出日時 2018-12-06 01:42:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 956 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 203,056 KB
実行使用メモリ 5,020 KB
最終ジャッジ日時 2023-10-11 09:16:04
合計ジャッジ時間 5,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 51 ms
4,832 KB
testcase_04 AC 23 ms
4,352 KB
testcase_05 AC 17 ms
4,348 KB
testcase_06 AC 16 ms
4,352 KB
testcase_07 AC 50 ms
5,020 KB
testcase_08 AC 26 ms
4,352 KB
testcase_09 AC 10 ms
4,352 KB
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 53 ms
4,944 KB
testcase_12 AC 13 ms
4,352 KB
testcase_13 AC 18 ms
4,348 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 8 ms
4,352 KB
testcase_17 AC 44 ms
4,560 KB
testcase_18 AC 24 ms
4,352 KB
testcase_19 AC 52 ms
4,892 KB
testcase_20 AC 15 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 53 ms
4,872 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 2 ms
4,352 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;
    fact = vector<long long>(n * 2);
    fact[0] = 1;
    for (int i = 1; i < n * 2; ++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