結果

問題 No.827 総神童数
ユーザー 夜
提出日時 2021-03-02 20:12:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 1,571 bytes
コンパイル時間 1,138 ms
コンパイル使用メモリ 102,412 KB
実行使用メモリ 22,044 KB
最終ジャッジ日時 2024-04-14 04:52:00
合計ジャッジ時間 8,761 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
14,232 KB
testcase_01 AC 23 ms
15,108 KB
testcase_02 AC 21 ms
14,104 KB
testcase_03 AC 21 ms
14,488 KB
testcase_04 AC 22 ms
14,868 KB
testcase_05 AC 23 ms
14,896 KB
testcase_06 AC 24 ms
14,940 KB
testcase_07 AC 22 ms
14,908 KB
testcase_08 AC 21 ms
14,364 KB
testcase_09 AC 273 ms
22,044 KB
testcase_10 AC 98 ms
17,432 KB
testcase_11 AC 24 ms
14,232 KB
testcase_12 AC 51 ms
15,896 KB
testcase_13 AC 216 ms
20,632 KB
testcase_14 AC 27 ms
14,236 KB
testcase_15 AC 89 ms
16,792 KB
testcase_16 AC 211 ms
20,836 KB
testcase_17 AC 252 ms
21,764 KB
testcase_18 AC 112 ms
17,432 KB
testcase_19 AC 304 ms
22,016 KB
testcase_20 AC 194 ms
20,352 KB
testcase_21 AC 134 ms
19,084 KB
testcase_22 AC 216 ms
20,836 KB
testcase_23 AC 23 ms
14,620 KB
testcase_24 AC 238 ms
21,336 KB
testcase_25 AC 201 ms
19,608 KB
testcase_26 AC 285 ms
21,276 KB
testcase_27 AC 175 ms
19,512 KB
testcase_28 AC 172 ms
19,484 KB
testcase_29 AC 135 ms
17,816 KB
testcase_30 AC 46 ms
15,512 KB
testcase_31 AC 94 ms
17,432 KB
testcase_32 AC 87 ms
17,056 KB
testcase_33 AC 262 ms
21,916 KB
testcase_34 AC 235 ms
21,528 KB
testcase_35 AC 95 ms
17,044 KB
testcase_36 AC 135 ms
18,928 KB
testcase_37 AC 174 ms
19,608 KB
testcase_38 AC 249 ms
21,784 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