結果

問題 No.758 VVVVV
ユーザー polylogKpolylogK
提出日時 2018-12-01 09:58:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,005 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 174,628 KB
実行使用メモリ 9,336 KB
最終ジャッジ日時 2023-08-04 04:29:22
合計ジャッジ時間 4,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 39 ms
9,200 KB
testcase_04 AC 18 ms
5,664 KB
testcase_05 AC 13 ms
4,964 KB
testcase_06 AC 11 ms
4,892 KB
testcase_07 AC 37 ms
9,016 KB
testcase_08 AC 20 ms
6,248 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 14 ms
5,240 KB
testcase_11 AC 39 ms
9,144 KB
testcase_12 AC 10 ms
4,608 KB
testcase_13 AC 13 ms
5,136 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 34 ms
8,348 KB
testcase_18 AC 19 ms
5,644 KB
testcase_19 AC 40 ms
9,024 KB
testcase_20 AC 11 ms
4,712 KB
testcase_21 AC 12 ms
4,880 KB
testcase_22 AC 44 ms
9,336 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

std::vector<std::vector<int>> g;
int count(int v = 0, int par = -1) {
	int ret = 0;
	bool f = true;
	for(auto e : g[v]) {
		if(e == par) continue;
		ret += count(e, v);
		f = false;
	}
	
	return ret + f;
}

const int MOD = 1e9 + 7;
i64 mod_pow(i64 x, int n = MOD - 2, int mod = MOD) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= MOD;
		(x *= x) %= MOD;
		n >>= 1;
	}
	return ret;
}

std::vector<i64> fact;
i64 comb(int n, int r) {
	return fact[n] * mod_pow(fact[n - r]) % MOD * mod_pow(fact[r]) % MOD;
}

int main() {
	int n; scanf("%d", &n); g.resize(n); fact.resize(n + 1, 1);
	for(i64 i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD;
	for(int i = 0; i < n - 1; i++) {
		int a, b; scanf("%d %d", &a, &b);
		
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}
	int k = count();
	
	printf("%lld\n", comb(n - 1, k - 1) * comb(n - 2, k - 1) % MOD * mod_pow(k) % MOD);
	return 0;
}
0