結果

問題 No.827 総神童数
ユーザー kappybarkappybar
提出日時 2020-04-14 14:36:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,182 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 169,940 KB
実行使用メモリ 24,304 KB
最終ジャッジ日時 2024-04-09 05:22:37
合計ジャッジ時間 10,215 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,660 KB
testcase_01 AC 6 ms
9,520 KB
testcase_02 AC 6 ms
9,564 KB
testcase_03 AC 6 ms
9,592 KB
testcase_04 AC 6 ms
9,584 KB
testcase_05 AC 5 ms
9,592 KB
testcase_06 AC 6 ms
9,588 KB
testcase_07 AC 6 ms
9,556 KB
testcase_08 AC 5 ms
9,696 KB
testcase_09 AC 358 ms
24,304 KB
testcase_10 AC 123 ms
14,092 KB
testcase_11 AC 11 ms
9,852 KB
testcase_12 AC 55 ms
11,716 KB
testcase_13 AC 281 ms
21,780 KB
testcase_14 AC 17 ms
10,040 KB
testcase_15 AC 113 ms
14,276 KB
testcase_16 AC 287 ms
18,680 KB
testcase_17 AC 338 ms
20,808 KB
testcase_18 AC 148 ms
15,308 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 200 ms
12,920 KB
testcase_22 WA -
testcase_23 AC 8 ms
9,480 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<ll> depth(n,0);

void dfs(int i,int p=-1,ll 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)%MOD;
    }
    cout << ans << endl;
    return 0;
}
0