結果

問題 No.827 総神童数
ユーザー ngtkanangtkana
提出日時 2020-03-30 00:37:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 1,124 bytes
コンパイル時間 2,452 ms
コンパイル使用メモリ 203,988 KB
実行使用メモリ 18,164 KB
最終ジャッジ日時 2023-08-30 20:08:57
合計ジャッジ時間 7,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 205 ms
17,472 KB
testcase_10 AC 69 ms
8,448 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 30 ms
5,424 KB
testcase_13 AC 167 ms
15,100 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 63 ms
7,684 KB
testcase_16 AC 165 ms
15,072 KB
testcase_17 AC 194 ms
16,904 KB
testcase_18 AC 82 ms
9,244 KB
testcase_19 AC 225 ms
18,164 KB
testcase_20 AC 158 ms
14,800 KB
testcase_21 AC 109 ms
11,152 KB
testcase_22 AC 169 ms
15,756 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 194 ms
16,904 KB
testcase_25 AC 140 ms
13,964 KB
testcase_26 AC 193 ms
16,748 KB
testcase_27 AC 124 ms
11,952 KB
testcase_28 AC 122 ms
11,844 KB
testcase_29 AC 97 ms
10,380 KB
testcase_30 AC 29 ms
5,432 KB
testcase_31 AC 76 ms
8,932 KB
testcase_32 AC 73 ms
8,700 KB
testcase_33 AC 223 ms
17,880 KB
testcase_34 AC 196 ms
16,780 KB
testcase_35 AC 76 ms
9,008 KB
testcase_36 AC 108 ms
10,968 KB
testcase_37 AC 143 ms
12,976 KB
testcase_38 AC 216 ms
17,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
lint mod=1'000'000'007;
lint inverse(lint x){
    lint ans=1;
    for(lint p=mod-2;p;p>>=1){
        if(p&1)ans=ans*x%mod;
        x=x*x%mod;
    }
    return ans;
}
struct mint{lint value;};
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::vector<lint>>g(n);
    for(lint i=0;i<n-1;i++){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<lint>depth(n,-1);
    std::vector<lint>que={0};
    depth.at(0)=0;
    for(lint i=0;i<(lint)que.size();i++){
        lint x=que.at(i);
        for(lint y:g.at(x)){
            if(depth.at(y)!=-1)continue;
            depth.at(y)=depth.at(x)+1;
            que.push_back(y);
        }
    }
    lint ans=std::accumulate(depth.begin(),depth.end(),0ll,
        [](lint acc,lint x){return acc+inverse(x+1);})%mod;
    if(ans<0)ans+=mod;
    for(lint i=1;i<=n;i++)ans=ans*i%mod;
    std::cout<<ans<<'\n';
}

0