結果

問題 No.827 総神童数
ユーザー 夜
提出日時 2021-03-02 20:12:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 100,520 KB
実行使用メモリ 21,944 KB
最終ジャッジ日時 2023-07-26 14:56:18
合計ジャッジ時間 10,059 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
13,476 KB
testcase_01 AC 18 ms
13,668 KB
testcase_02 AC 18 ms
13,424 KB
testcase_03 AC 18 ms
13,396 KB
testcase_04 AC 19 ms
13,620 KB
testcase_05 AC 19 ms
13,416 KB
testcase_06 AC 18 ms
13,580 KB
testcase_07 AC 19 ms
13,400 KB
testcase_08 AC 19 ms
13,420 KB
testcase_09 AC 214 ms
21,944 KB
testcase_10 AC 80 ms
16,700 KB
testcase_11 AC 20 ms
13,836 KB
testcase_12 AC 45 ms
15,144 KB
testcase_13 AC 169 ms
20,332 KB
testcase_14 AC 24 ms
14,024 KB
testcase_15 AC 74 ms
16,392 KB
testcase_16 AC 168 ms
20,264 KB
testcase_17 AC 205 ms
21,392 KB
testcase_18 AC 92 ms
17,480 KB
testcase_19 AC 249 ms
21,852 KB
testcase_20 AC 171 ms
19,880 KB
testcase_21 AC 118 ms
18,240 KB
testcase_22 AC 190 ms
20,392 KB
testcase_23 AC 19 ms
13,792 KB
testcase_24 AC 215 ms
21,020 KB
testcase_25 AC 156 ms
19,280 KB
testcase_26 AC 211 ms
20,828 KB
testcase_27 AC 134 ms
18,568 KB
testcase_28 AC 130 ms
18,616 KB
testcase_29 AC 107 ms
17,872 KB
testcase_30 AC 42 ms
14,900 KB
testcase_31 AC 85 ms
16,716 KB
testcase_32 AC 80 ms
16,800 KB
testcase_33 AC 228 ms
21,656 KB
testcase_34 AC 204 ms
20,964 KB
testcase_35 AC 85 ms
17,084 KB
testcase_36 AC 118 ms
18,232 KB
testcase_37 AC 159 ms
19,284 KB
testcase_38 AC 230 ms
21,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long fac[200020], finv[200020], inv[200020];
long long mod = 1000000007;
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 200020; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COM(long long n, long long k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
long long k[200020], co[200020] = {};
vector<vector<int>> vec(200020);
bool bo[200020] = { false };
int main(){
	COMinit();
	int n;
	cin >> n;
	k[0] = 1;
	long long k1 = 1;
	for (long long i = 1; i <= n; i++) {
		k1 *= i;
		k1 %= mod;
		k[i] = k1;
	}
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		vec[u].emplace_back(v);
		vec[v].emplace_back(u);
	}
	queue<int> que;
	que.push(1);
	bo[1] = true;
	while (!que.empty()) {
		int now = que.front();
		for (int i = 0; i < vec[now].size(); i++) {
			if (!bo[vec[now][i]]) {
				co[vec[now][i]] = co[now] + 1;
				que.push(vec[now][i]);
				bo[vec[now][i]] = true;
			}
		}
		que.pop();
	}
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += COM(n, co[i] + 1) * k[co[i]] % mod * k[n - co[i] - 1] % mod;
		ans %= mod;
	}
	cout << ans << endl;
}
0