結果

問題 No.827 総神童数
ユーザー kotatsugamekotatsugame
提出日時 2019-05-04 01:23:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 70,612 KB
実行使用メモリ 30,200 KB
最終ジャッジ日時 2023-08-30 20:30:21
合計ジャッジ時間 9,637 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
12,668 KB
testcase_01 AC 9 ms
12,652 KB
testcase_02 AC 10 ms
12,520 KB
testcase_03 AC 9 ms
12,508 KB
testcase_04 AC 10 ms
12,704 KB
testcase_05 AC 10 ms
12,592 KB
testcase_06 AC 10 ms
12,760 KB
testcase_07 AC 9 ms
12,688 KB
testcase_08 AC 10 ms
12,520 KB
testcase_09 AC 385 ms
30,200 KB
testcase_10 AC 133 ms
17,956 KB
testcase_11 AC 16 ms
12,772 KB
testcase_12 AC 63 ms
15,540 KB
testcase_13 AC 306 ms
27,200 KB
testcase_14 AC 22 ms
13,168 KB
testcase_15 AC 125 ms
18,416 KB
testcase_16 AC 304 ms
23,004 KB
testcase_17 AC 358 ms
25,800 KB
testcase_18 AC 159 ms
19,464 KB
testcase_19 AC 379 ms
18,788 KB
testcase_20 AC 272 ms
17,120 KB
testcase_21 AC 198 ms
15,828 KB
testcase_22 AC 306 ms
17,544 KB
testcase_23 AC 12 ms
12,548 KB
testcase_24 AC 336 ms
18,172 KB
testcase_25 AC 249 ms
16,948 KB
testcase_26 AC 337 ms
18,156 KB
testcase_27 AC 222 ms
16,248 KB
testcase_28 AC 223 ms
16,280 KB
testcase_29 AC 179 ms
15,512 KB
testcase_30 AC 59 ms
13,684 KB
testcase_31 AC 138 ms
14,948 KB
testcase_32 AC 133 ms
14,840 KB
testcase_33 AC 376 ms
18,496 KB
testcase_34 AC 339 ms
18,060 KB
testcase_35 AC 139 ms
14,896 KB
testcase_36 AC 195 ms
15,780 KB
testcase_37 AC 253 ms
16,808 KB
testcase_38 AC 367 ms
18,572 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;
	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,0);
	F[0]=1;
	for(int i=1;i<2<<17;i++)F[i]=F[i-1]*i%mod;
	long ans=0;
	for(int i=0;i<N;i++)
	{
		(ans+=F[N]*(N-d[i])%mod*power((d[i]+1)*F[N-d[i]]%mod,mod-2)%mod*F[N-1-d[i]]%mod)%=mod;
	}
	cout<<ans<<endl;
}
0