結果
問題 | No.758 VVVVV |
ユーザー |
![]() |
提出日時 | 2018-12-06 01:44:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 2,160 ms |
コンパイル使用メモリ | 198,796 KB |
最終ジャッジ日時 | 2025-01-06 18:22:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 * 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;}