結果

問題 No.827 総神童数
ユーザー kotatsugame
提出日時 2019-05-04 01:23:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 67,856 KB
実行使用メモリ 29,952 KB
最終ジャッジ日時 2025-01-02 16:51:29
合計ジャッジ時間 9,013 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:15:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-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