結果

問題 No.827 総神童数
ユーザー chocoruskchocorusk
提出日時 2019-05-03 21:45:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,525 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 98,772 KB
実行使用メモリ 27,812 KB
最終ジャッジ日時 2023-08-30 06:03:01
合計ジャッジ時間 5,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,568 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 4 ms
10,684 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[1500001], invf[1500001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(x<y) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
vector<int> g[200020];
int d[200020];
bool used[200020];
void dfs(int x){
    used[x]=1;
    for(auto y:g[x]){
        if(!used[y]){
            d[y]=d[x]+1;
            dfs(y);
        }
    }
}
int main()
{
    int n; cin>>n;
    for(int i=0; i<n-1; i++){
        int u, v; cin>>u>>v; u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    d[0]=1;
    dfs(0);
    fac(n);
    ll ans=0;
    for(int i=0; i<n; i++){
        ans+=comb(n, d[i])*f[n-d[i]]%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0