結果

問題 No.827 総神童数
ユーザー matsukin1111matsukin1111
提出日時 2019-05-27 10:38:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 862 ms
コンパイル使用メモリ 97,420 KB
実行使用メモリ 27,860 KB
最終ジャッジ日時 2023-10-17 18:11:21
合計ジャッジ時間 6,072 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
13,036 KB
testcase_01 AC 9 ms
13,100 KB
testcase_02 AC 9 ms
13,104 KB
testcase_03 AC 9 ms
13,100 KB
testcase_04 AC 9 ms
13,100 KB
testcase_05 AC 9 ms
13,104 KB
testcase_06 AC 10 ms
13,100 KB
testcase_07 AC 9 ms
13,036 KB
testcase_08 AC 9 ms
13,100 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #


#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll,ll>pll;

int n;
vector<int>e[201010];
ll ans = 0;

const int MAX = 201010;
ll fac[MAX], finv[MAX], inv[MAX];
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void dfs(int cu,int pa,int dpt) {
	ans += comb(n,dpt)*fac[dpt-1]*fac[n-dpt];
	ans %= MOD;
	fore(to, e[cu])if (to != pa)dfs(to,cu,dpt+1);
}


int main(){
	cin >> n;
	combinit();
	rep(i, 0, n - 1) {
		int a, b;
		cin >> a >> b;
		e[a].pb(b);
		e[b].pb(a);
	}
	dfs(1,-1,1);
	cout << ans << endl;

	return 0;
}
0