結果

問題 No.827 総神童数
ユーザー gazelle
提出日時 2019-05-03 23:08:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,637 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 117,612 KB
最終ジャッジ日時 2025-01-07 03:31:22
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other AC * 1 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
using namespace std;
using lint = long long;
using ld = long double;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(lint i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int n;
vector<vector<int>> tree;
lint ans = 0;

lint _pow(lint a, lint n) {
	if(n == 0) return 1;
	else {
		lint res = 1;
		lint buf = a;
		while(n > 0) {
			if(n % 2 == 1) {
				res *= buf;
				res %= MOD;
			}
			buf *= buf;
			buf %= MOD;
			n/=2;
		}
		return res;
	}
}

lint factoria[202020];

void dfs(int pos, int par, int height) {
	ans += factoria[n] * _pow(factoria[height - 1], MOD - 2);
	ans %= MOD;
	REP(i, tree[pos].size()) {
		if(tree[pos][i] == par) continue;
		dfs(tree[pos][i], pos, height + 1);
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	factoria[0] = 1;
	FOR(i, 1, 202020) {
		factoria[i] = factoria[i - 1] * i;
		factoria[i] %= MOD;
	}
	cin >> n;
	tree.resize(n);
	REP(i, n - 1) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		tree[u].pb(v);
		tree[v].pb(u);
	}
	dfs(0, -1, 1);
	cout << (ans % MOD + MOD) % MOD << endl;
	return 0;
}
/* --------------------------------------- */
0