結果
| 問題 |
No.758 VVVVV
|
| コンテスト | |
| ユーザー |
りあん
|
| 提出日時 | 2018-12-06 01:45:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 1,013 bytes |
| コンパイル時間 | 1,874 ms |
| コンパイル使用メモリ | 197,664 KB |
| 最終ジャッジ日時 | 2025-01-06 18:22:36 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#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;
}
りあん