結果

問題 No.827 総神童数
ユーザー pockynypockyny
提出日時 2019-06-26 21:51:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 76,192 KB
実行使用メモリ 22,816 KB
最終ジャッジ日時 2023-09-08 11:27:10
合計ジャッジ時間 6,082 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,712 KB
testcase_01 AC 10 ms
10,712 KB
testcase_02 AC 11 ms
10,716 KB
testcase_03 AC 11 ms
10,644 KB
testcase_04 AC 11 ms
10,636 KB
testcase_05 AC 10 ms
10,808 KB
testcase_06 AC 11 ms
10,736 KB
testcase_07 AC 11 ms
10,716 KB
testcase_08 AC 10 ms
10,724 KB
testcase_09 AC 194 ms
22,816 KB
testcase_10 AC 67 ms
14,812 KB
testcase_11 AC 12 ms
10,844 KB
testcase_12 AC 34 ms
12,724 KB
testcase_13 AC 153 ms
20,660 KB
testcase_14 AC 15 ms
11,160 KB
testcase_15 AC 64 ms
14,904 KB
testcase_16 AC 153 ms
18,844 KB
testcase_17 AC 184 ms
20,660 KB
testcase_18 AC 79 ms
15,904 KB
testcase_19 AC 215 ms
18,400 KB
testcase_20 AC 150 ms
16,384 KB
testcase_21 AC 103 ms
15,188 KB
testcase_22 AC 173 ms
16,788 KB
testcase_23 AC 11 ms
10,972 KB
testcase_24 AC 186 ms
17,448 KB
testcase_25 AC 135 ms
16,164 KB
testcase_26 AC 186 ms
17,496 KB
testcase_27 AC 117 ms
15,500 KB
testcase_28 AC 112 ms
15,576 KB
testcase_29 AC 88 ms
14,680 KB
testcase_30 AC 33 ms
11,900 KB
testcase_31 AC 70 ms
13,720 KB
testcase_32 AC 69 ms
13,616 KB
testcase_33 AC 211 ms
17,972 KB
testcase_34 AC 186 ms
17,456 KB
testcase_35 AC 71 ms
13,788 KB
testcase_36 AC 101 ms
14,928 KB
testcase_37 AC 143 ms
15,912 KB
testcase_38 AC 203 ms
17,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;
vector<ll> G[200010];
ll d[200010],mod = 1000000007,inv[200010],ans = 0;
void solve(){
	inv[1] = 1;
	for(int i=2;i<=200000;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
}
void dfs(int s, int p){
	for(int v:G[s]){
		if(v==p) continue;
		d[v] = d[s] + 1;
		dfs(v,s);
	}
}
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n-1;i++){
		int a,b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	d[0] = 1;
	dfs(0,-1);
	solve();
	ll f = 1;
	for(i=2;i<=n;i++){
		(f *= i) %= mod;
	}
	for(i=0;i<n;i++){
		(ans += f*inv[d[i]]%mod) %= mod;
	}
	cout << ans << endl;
}
0