結果

問題 No.827 総神童数
ユーザー kappybarkappybar
提出日時 2020-04-14 14:24:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 171,132 KB
実行使用メモリ 23,188 KB
最終ジャッジ日時 2023-07-24 22:02:59
合計ジャッジ時間 11,463 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,516 KB
testcase_01 AC 5 ms
8,560 KB
testcase_02 AC 5 ms
8,468 KB
testcase_03 AC 4 ms
8,472 KB
testcase_04 AC 5 ms
8,228 KB
testcase_05 AC 5 ms
8,456 KB
testcase_06 AC 5 ms
8,232 KB
testcase_07 AC 5 ms
8,516 KB
testcase_08 AC 5 ms
8,352 KB
testcase_09 AC 333 ms
23,188 KB
testcase_10 AC 114 ms
13,048 KB
testcase_11 AC 10 ms
8,668 KB
testcase_12 AC 52 ms
10,780 KB
testcase_13 AC 264 ms
20,608 KB
testcase_14 AC 14 ms
9,044 KB
testcase_15 AC 107 ms
13,272 KB
testcase_16 AC 265 ms
17,564 KB
testcase_17 AC 321 ms
19,876 KB
testcase_18 AC 137 ms
14,372 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 180 ms
11,916 KB
testcase_22 WA -
testcase_23 AC 6 ms
8,164 KB
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 <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> depth(n,0);

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

long long modpow(long long a, long long b,long long mod){
        bitset<30> bit(b);
        string s = bit.to_string();
        long long ret = 1;
        for (int i = 0;i< s.length(); ++i){
                ret = (ret * ret) % mod;
                if(s[i]-'0') ret = (ret * a) % mod;
        }
        return ret;
}

long long inverse(long long x,long long mod){
    return modpow(x,mod-2,mod);
}

int main(){
    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;
    ll n_p = 1;
    for(ll i=1;i<=n;i++) n_p = (n_p * i)%MOD;
    for(ll i=0;i<n;i++){
        ans = (ans + n_p * (inverse(i+1,MOD) * depth[i])%MOD)%MOD;
    }
    cout << ans << endl;
    return 0;
}
0