結果

問題 No.827 総神童数
ユーザー chocoruskchocorusk
提出日時 2019-05-03 21:46:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,535 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 98,504 KB
実行使用メモリ 27,512 KB
最終ジャッジ日時 2023-08-30 06:03:53
合計ジャッジ時間 5,788 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,788 KB
testcase_01 AC 4 ms
10,528 KB
testcase_02 AC 4 ms
10,560 KB
testcase_03 AC 4 ms
10,720 KB
testcase_04 AC 4 ms
10,528 KB
testcase_05 AC 5 ms
10,540 KB
testcase_06 AC 4 ms
10,784 KB
testcase_07 AC 4 ms
10,556 KB
testcase_08 AC 4 ms
10,560 KB
testcase_09 AC 180 ms
27,512 KB
testcase_10 AC 60 ms
16,748 KB
testcase_11 AC 6 ms
10,776 KB
testcase_12 AC 27 ms
12,568 KB
testcase_13 AC 142 ms
25,260 KB
testcase_14 AC 9 ms
10,940 KB
testcase_15 AC 56 ms
16,756 KB
testcase_16 AC 144 ms
23,440 KB
testcase_17 AC 172 ms
25,112 KB
testcase_18 AC 72 ms
17,924 KB
testcase_19 AC 202 ms
21,860 KB
testcase_20 AC 138 ms
19,844 KB
testcase_21 AC 92 ms
16,404 KB
testcase_22 AC 153 ms
20,388 KB
testcase_23 AC 5 ms
10,600 KB
testcase_24 AC 177 ms
20,928 KB
testcase_25 AC 127 ms
17,428 KB
testcase_26 AC 173 ms
21,156 KB
testcase_27 AC 107 ms
16,808 KB
testcase_28 AC 107 ms
17,044 KB
testcase_29 AC 82 ms
15,976 KB
testcase_30 AC 25 ms
11,752 KB
testcase_31 AC 65 ms
15,244 KB
testcase_32 AC 63 ms
15,312 KB
testcase_33 AC 193 ms
21,572 KB
testcase_34 AC 169 ms
20,912 KB
testcase_35 AC 62 ms
15,368 KB
testcase_36 AC 88 ms
16,360 KB
testcase_37 AC 122 ms
17,404 KB
testcase_38 AC 191 ms
21,396 KB
権限があれば一括ダウンロードができます

ソースコード

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*f[d[i]-1];
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0