結果

問題 No.827 総神童数
ユーザー kotatsugamekotatsugame
提出日時 2019-05-04 01:26:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 770 ms
コンパイル使用メモリ 70,916 KB
実行使用メモリ 29,692 KB
最終ジャッジ日時 2023-08-30 20:40:12
合計ジャッジ時間 8,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,608 KB
testcase_01 AC 5 ms
11,540 KB
testcase_02 AC 5 ms
11,552 KB
testcase_03 AC 5 ms
11,520 KB
testcase_04 AC 5 ms
11,592 KB
testcase_05 AC 5 ms
11,536 KB
testcase_06 AC 4 ms
11,532 KB
testcase_07 AC 4 ms
11,532 KB
testcase_08 AC 5 ms
11,552 KB
testcase_09 AC 365 ms
29,692 KB
testcase_10 AC 125 ms
16,908 KB
testcase_11 AC 10 ms
11,796 KB
testcase_12 AC 57 ms
14,420 KB
testcase_13 AC 290 ms
26,436 KB
testcase_14 AC 16 ms
12,244 KB
testcase_15 AC 117 ms
17,496 KB
testcase_16 AC 293 ms
22,260 KB
testcase_17 AC 345 ms
25,196 KB
testcase_18 AC 151 ms
18,808 KB
testcase_19 AC 369 ms
18,252 KB
testcase_20 AC 261 ms
16,448 KB
testcase_21 AC 188 ms
14,920 KB
testcase_22 AC 291 ms
16,708 KB
testcase_23 AC 6 ms
11,580 KB
testcase_24 AC 324 ms
17,508 KB
testcase_25 AC 241 ms
15,720 KB
testcase_26 AC 322 ms
17,652 KB
testcase_27 AC 218 ms
15,216 KB
testcase_28 AC 207 ms
15,368 KB
testcase_29 AC 169 ms
14,452 KB
testcase_30 AC 52 ms
12,492 KB
testcase_31 AC 130 ms
13,936 KB
testcase_32 AC 125 ms
13,736 KB
testcase_33 AC 362 ms
17,984 KB
testcase_34 AC 326 ms
17,340 KB
testcase_35 AC 130 ms
13,896 KB
testcase_36 AC 186 ms
14,916 KB
testcase_37 AC 242 ms
15,712 KB
testcase_38 AC 349 ms
17,860 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:15:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   15 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
long mod=1e9+7,F[2<<17];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int d[2<<17];
vector<int>G[2<<17];
void dfs(int u,int p,int di)
{
	d[u]=di;
	for(int i=0;i<G[u].size();i++)
		if(G[u][i]!=p)dfs(G[u][i],u,di+1);
}
int N;
main()
{
	cin>>N;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1,1);
	long ans=0;
	for(int i=0;i<N;i++)
	{
		(ans+=F[N]*power(d[i],mod-2))%=mod;
	}
	cout<<ans<<endl;
}
0