結果

問題 No.827 総神童数
ユーザー ngtkanangtkana
提出日時 2020-03-30 00:32:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,222 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 205,192 KB
実行使用メモリ 19,324 KB
最終ジャッジ日時 2023-08-30 20:08:43
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 99 ms
18,356 KB
testcase_10 AC 31 ms
8,736 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 13 ms
5,520 KB
testcase_13 AC 79 ms
15,592 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 28 ms
7,980 KB
testcase_16 AC 74 ms
15,680 KB
testcase_17 AC 91 ms
17,928 KB
testcase_18 AC 39 ms
9,640 KB
testcase_19 AC 120 ms
19,324 KB
testcase_20 AC 79 ms
15,080 KB
testcase_21 AC 52 ms
11,956 KB
testcase_22 AC 84 ms
16,108 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 102 ms
17,500 KB
testcase_25 AC 74 ms
13,916 KB
testcase_26 AC 103 ms
17,620 KB
testcase_27 AC 61 ms
12,804 KB
testcase_28 AC 56 ms
12,536 KB
testcase_29 AC 46 ms
10,828 KB
testcase_30 AC 14 ms
5,536 KB
testcase_31 AC 35 ms
9,216 KB
testcase_32 AC 33 ms
8,924 KB
testcase_33 AC 110 ms
18,964 KB
testcase_34 AC 98 ms
17,496 KB
testcase_35 AC 35 ms
9,288 KB
testcase_36 AC 51 ms
11,740 KB
testcase_37 AC 68 ms
13,956 KB
testcase_38 AC 109 ms
18,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using lint=long long;
using real=long double;
lint mod=1'000'000'007;
lint normalize(lint x){return x<0?x+mod:x;}
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,
        [inverse=[n]{
            std::vector<lint>inverse(n+1,1);
            for(lint i=2;i<=n;i++){
                inverse.at(i)=normalize(-inverse.at(mod%i)*(mod/i)%mod);
            }
            return inverse;
        }()](lint acc,lint x){return acc+inverse.at(x+1);})%mod;
    if(ans<0)ans+=mod;
    for(lint i=1;i<=n;i++)ans=ans*i%mod;
    std::cout<<ans<<'\n';
}
0