結果

問題 No.827 総神童数
ユーザー kappybarkappybar
提出日時 2020-04-14 15:12:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 997 bytes
コンパイル時間 3,262 ms
コンパイル使用メモリ 170,020 KB
実行使用メモリ 41,640 KB
最終ジャッジ日時 2024-04-09 05:23:36
合計ジャッジ時間 9,187 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
26,848 KB
testcase_01 AC 21 ms
26,908 KB
testcase_02 AC 21 ms
26,736 KB
testcase_03 AC 22 ms
26,840 KB
testcase_04 AC 22 ms
26,904 KB
testcase_05 AC 21 ms
26,736 KB
testcase_06 AC 21 ms
26,760 KB
testcase_07 AC 24 ms
29,032 KB
testcase_08 AC 20 ms
26,864 KB
testcase_09 AC 211 ms
41,640 KB
testcase_10 AC 85 ms
31,360 KB
testcase_11 AC 26 ms
27,016 KB
testcase_12 AC 46 ms
29,156 KB
testcase_13 AC 168 ms
39,056 KB
testcase_14 AC 25 ms
27,232 KB
testcase_15 AC 75 ms
31,656 KB
testcase_16 AC 168 ms
35,932 KB
testcase_17 AC 196 ms
38,108 KB
testcase_18 AC 91 ms
32,576 KB
testcase_19 AC 235 ms
33,016 KB
testcase_20 AC 173 ms
31,444 KB
testcase_21 AC 128 ms
30,104 KB
testcase_22 AC 186 ms
31,748 KB
testcase_23 AC 21 ms
26,920 KB
testcase_24 AC 200 ms
32,196 KB
testcase_25 AC 155 ms
30,920 KB
testcase_26 AC 214 ms
32,292 KB
testcase_27 AC 131 ms
30,604 KB
testcase_28 AC 183 ms
32,412 KB
testcase_29 AC 114 ms
29,644 KB
testcase_30 AC 43 ms
27,896 KB
testcase_31 AC 82 ms
29,128 KB
testcase_32 AC 82 ms
29,008 KB
testcase_33 AC 239 ms
32,888 KB
testcase_34 AC 203 ms
32,288 KB
testcase_35 AC 88 ms
29,048 KB
testcase_36 AC 124 ms
30,096 KB
testcase_37 AC 149 ms
31,168 KB
testcase_38 AC 227 ms
32,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const ll INF = 1e14;
const int MOD = 1000000007;
int n = 200005;
vector<vector<int>> tree(n,vector<int>());
vector<ll> depth(n,0);

void dfs(int i,int p=-1,int d=0){
    depth[i] = d;
    for(int c:tree[i]){
        if(c==p) continue;
        dfs(c,i,d+1);
    }
}

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];


void init() {
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    }
}

int main(){
    init();
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0);
    ll ans = 0;
    rep(i,n){
        ans = (ans + inv[depth[i]+1])%MOD;
    }
    ans = (ans * fac[n])%MOD;
    cout << ans << endl;
    return 0;
}
0