結果

問題 No.827 総神童数
ユーザー totori_nyaatotori_nyaa
提出日時 2019-08-06 21:40:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 2,579 ms
コンパイル使用メモリ 168,080 KB
実行使用メモリ 20,808 KB
最終ジャッジ日時 2023-09-25 18:13:34
合計ジャッジ時間 7,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,376 KB
testcase_01 AC 5 ms
8,320 KB
testcase_02 AC 5 ms
8,324 KB
testcase_03 AC 5 ms
8,432 KB
testcase_04 AC 5 ms
8,424 KB
testcase_05 AC 5 ms
8,428 KB
testcase_06 AC 4 ms
8,336 KB
testcase_07 AC 5 ms
8,500 KB
testcase_08 AC 5 ms
8,536 KB
testcase_09 AC 151 ms
20,808 KB
testcase_10 AC 45 ms
12,336 KB
testcase_11 AC 7 ms
8,720 KB
testcase_12 AC 22 ms
10,412 KB
testcase_13 AC 118 ms
18,324 KB
testcase_14 AC 7 ms
9,008 KB
testcase_15 AC 43 ms
12,368 KB
testcase_16 AC 121 ms
16,620 KB
testcase_17 AC 137 ms
18,400 KB
testcase_18 AC 55 ms
13,440 KB
testcase_19 AC 155 ms
15,100 KB
testcase_20 AC 96 ms
13,140 KB
testcase_21 AC 63 ms
11,992 KB
testcase_22 AC 115 ms
13,740 KB
testcase_23 AC 5 ms
8,380 KB
testcase_24 AC 123 ms
14,260 KB
testcase_25 AC 92 ms
13,016 KB
testcase_26 AC 133 ms
14,156 KB
testcase_27 AC 74 ms
12,452 KB
testcase_28 AC 81 ms
12,340 KB
testcase_29 AC 61 ms
11,540 KB
testcase_30 AC 19 ms
9,484 KB
testcase_31 AC 45 ms
10,932 KB
testcase_32 AC 44 ms
10,840 KB
testcase_33 AC 146 ms
14,748 KB
testcase_34 AC 147 ms
14,156 KB
testcase_35 AC 46 ms
10,856 KB
testcase_36 AC 64 ms
11,912 KB
testcase_37 AC 90 ms
12,896 KB
testcase_38 AC 142 ms
14,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


const long long mod = 1e9+7;

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}
 

ll n;
vector<vector<int>> v(200100);
bool used[200100];

vector<int> dep(200010);

void dfs(int p,int d){
    used[p]=1;
    d++;
    dep[p]=d;
    for(auto i:v[p]){
        if(!used[i]){
            dfs(i,d);
        }
    }
}

signed main(){
    //cout << setprecision(12) ;
    ios::sync_with_stdio(false);
	cin.tie(0);


    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }    
    dfs(0,0);
    ll ans=0;
    for(int i=0;i<n;i++){
        ans += modinv(dep[i]);
    }
    for(int i=1;i<=n;i++){
        ans*=i;
        ans%=mod;
    }
    cout<<ans<<endl;


    
}
0