結果

問題 No.758 VVVVV
ユーザー finefine
提出日時 2018-12-27 20:23:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 167,416 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-22 03:04:44
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 36 ms
9,984 KB
testcase_04 AC 16 ms
6,400 KB
testcase_05 AC 12 ms
5,504 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 32 ms
9,984 KB
testcase_08 AC 16 ms
6,656 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 11 ms
5,632 KB
testcase_11 AC 33 ms
10,112 KB
testcase_12 AC 9 ms
5,376 KB
testcase_13 AC 11 ms
5,504 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 27 ms
9,088 KB
testcase_18 AC 15 ms
6,528 KB
testcase_19 AC 33 ms
10,240 KB
testcase_20 AC 10 ms
5,376 KB
testcase_21 AC 10 ms
5,376 KB
testcase_22 AC 33 ms
10,368 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;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll f[200000], fi[200000];

void init(int n) {
	f[0] = 1;
	for (int i = 1; i < n; i++) {
		f[i] = f[i - 1] * i % MOD;
	}
	fi[n - 1] = modpow(f[n - 1], MOD - 2);
	for (int i = n - 1; i > 0; i--) {
		fi[i - 1] = fi[i] * i % MOD;
	}
}

ll comb(int r, int c) {
	if (r < c) return 0;
	return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;

	if (n <= 2) {
		cout << 1 << endl;
		return 0;
	}

	vector< vector<int> > g(n);
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int cnt = 0;
	for (int i = 1; i < n; i++) {
		cnt += (g[i].size() == 1);
	}

	init(n);
	cout << comb(n - 1, cnt - 1) * comb(n - 2, cnt - 1) % MOD * modpow(cnt, MOD - 2) % MOD << endl;
	return 0;
}
0