結果
| 問題 |
No.827 総神童数
|
| コンテスト | |
| ユーザー |
DAyamaCTF
|
| 提出日時 | 2019-05-11 08:49:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 183 ms / 2,000 ms |
| コード長 | 1,400 bytes |
| コンパイル時間 | 1,653 ms |
| コンパイル使用メモリ | 162,948 KB |
| 実行使用メモリ | 28,800 KB |
| 最終ジャッジ日時 | 2024-07-02 01:08:51 |
| 合計ジャッジ時間 | 6,559 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
ll fac[200010],finv[200010];
ll comb(ll n,ll r){
if(n<0||r<0||n<r)return 0;
else return (fac[n]*finv[n-r]%mod)*finv[r]%mod;
}
ll mod_pow(ll a,ll n){
ll res=1;
while(n>0){
if(n&1)res=res*a%mod;
a=a*a%mod;
n>>=1;
}
return res;
}
ll n;
vector<ll> g[200010];
ll res=0;
void dfs(ll v,ll pre,ll d){
for(ll nv : g[v]){
if(nv==pre)continue;
dfs(nv,v,d+1);
}
ll add=fac[d]*comb(n,d+1)%mod;
add*=fac[n-1-d]; add%=mod;
res+=add; res%=mod;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
fac[0]=1;
rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);
cin>>n;
rep(i,n-1){
ll a,b;
cin>>a>>b;
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
dfs(0,-1,0);
cout<<res<<endl;
return 0;
}
DAyamaCTF