結果

問題 No.827 総神童数
ユーザー kotatsugame
提出日時 2019-05-04 01:28:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 527 bytes
コンパイル時間 896 ms
コンパイル使用メモリ 68,820 KB
実行使用メモリ 28,156 KB
最終ジャッジ日時 2025-01-02 17:27:41
合計ジャッジ時間 8,757 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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=1,ans;
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;)
	{
		F=F*i%mod;
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1,1);
	for(int i=0;i<N;i++)ans+=power(d[i],mod-2);
	cout<<ans%mod*F%mod<<endl;
}
0