結果

問題 No.827 総神童数
ユーザー 👑 kmjpkmjp
提出日時 2019-05-03 21:36:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,310 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 168,988 KB
実行使用メモリ 29,880 KB
最終ジャッジ日時 2023-08-30 05:58:26
合計ジャッジ時間 6,312 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
17,432 KB
testcase_01 AC 25 ms
17,496 KB
testcase_02 AC 25 ms
17,500 KB
testcase_03 AC 24 ms
17,688 KB
testcase_04 AC 24 ms
17,680 KB
testcase_05 AC 24 ms
17,484 KB
testcase_06 AC 25 ms
17,612 KB
testcase_07 AC 24 ms
17,488 KB
testcase_08 AC 25 ms
17,548 KB
testcase_09 AC 127 ms
29,880 KB
testcase_10 AC 56 ms
21,424 KB
testcase_11 AC 25 ms
17,744 KB
testcase_12 AC 37 ms
19,412 KB
testcase_13 AC 110 ms
27,592 KB
testcase_14 AC 27 ms
17,956 KB
testcase_15 AC 51 ms
21,496 KB
testcase_16 AC 103 ms
25,740 KB
testcase_17 AC 119 ms
27,504 KB
testcase_18 AC 59 ms
22,452 KB
testcase_19 AC 147 ms
24,400 KB
testcase_20 AC 104 ms
22,580 KB
testcase_21 AC 74 ms
21,168 KB
testcase_22 AC 107 ms
23,108 KB
testcase_23 AC 25 ms
17,600 KB
testcase_24 AC 127 ms
23,744 KB
testcase_25 AC 92 ms
22,360 KB
testcase_26 AC 126 ms
23,612 KB
testcase_27 AC 84 ms
21,580 KB
testcase_28 AC 85 ms
21,492 KB
testcase_29 AC 67 ms
20,712 KB
testcase_30 AC 36 ms
18,496 KB
testcase_31 AC 57 ms
20,052 KB
testcase_32 AC 60 ms
20,000 KB
testcase_33 AC 134 ms
24,200 KB
testcase_34 AC 121 ms
23,684 KB
testcase_35 AC 57 ms
20,056 KB
testcase_36 AC 71 ms
21,100 KB
testcase_37 AC 85 ms
22,156 KB
testcase_38 AC 120 ms
24,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[202020];
int D[202020];

const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
ll mo=1000000007;

void dfs(int cur,int pre) {
	D[cur]=D[pre]+1;
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x].push_back(y);
		E[y].push_back(x);
	}
	dfs(1,0);
	
	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	ll ret=0;
	for(i=1;i<=N;i++) {
		(ret+=fact[N]*inv[D[i]])%=mo;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0