結果

問題 No.827 総神童数
ユーザー kappybarkappybar
提出日時 2020-04-14 14:30:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 169,212 KB
実行使用メモリ 23,412 KB
最終ジャッジ日時 2024-04-09 05:21:29
合計ジャッジ時間 10,185 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,788 KB
testcase_01 AC 5 ms
8,856 KB
testcase_02 AC 4 ms
8,764 KB
testcase_03 AC 4 ms
8,792 KB
testcase_04 AC 4 ms
8,708 KB
testcase_05 AC 5 ms
8,712 KB
testcase_06 AC 5 ms
8,816 KB
testcase_07 AC 5 ms
8,784 KB
testcase_08 AC 4 ms
8,628 KB
testcase_09 AC 340 ms
23,412 KB
testcase_10 AC 118 ms
13,256 KB
testcase_11 AC 10 ms
9,088 KB
testcase_12 AC 53 ms
10,948 KB
testcase_13 AC 273 ms
20,872 KB
testcase_14 AC 15 ms
9,156 KB
testcase_15 AC 108 ms
13,552 KB
testcase_16 AC 279 ms
17,984 KB
testcase_17 AC 326 ms
20,020 KB
testcase_18 AC 142 ms
14,700 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 178 ms
12,088 KB
testcase_22 WA -
testcase_23 AC 7 ms
8,864 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)%MOD;
    }
    cout << ans << endl;
    return 0;
}
0