結果

問題 No.827 総神童数
ユーザー ngtkanangtkana
提出日時 2020-03-30 00:14:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 205,200 KB
実行使用メモリ 18,180 KB
最終ジャッジ日時 2023-08-30 20:07:27
合計ジャッジ時間 7,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,500 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 147 ms
17,336 KB
testcase_10 AC 43 ms
8,296 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 18 ms
5,276 KB
testcase_13 AC 115 ms
15,000 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 39 ms
7,676 KB
testcase_16 AC 106 ms
14,936 KB
testcase_17 AC 130 ms
16,852 KB
testcase_18 AC 50 ms
9,092 KB
testcase_19 AC 146 ms
18,180 KB
testcase_20 AC 101 ms
14,816 KB
testcase_21 AC 61 ms
11,004 KB
testcase_22 AC 101 ms
15,808 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 118 ms
16,704 KB
testcase_25 AC 80 ms
14,088 KB
testcase_26 AC 115 ms
16,928 KB
testcase_27 AC 67 ms
11,808 KB
testcase_28 AC 67 ms
11,880 KB
testcase_29 AC 53 ms
10,296 KB
testcase_30 AC 16 ms
5,492 KB
testcase_31 AC 44 ms
9,084 KB
testcase_32 AC 42 ms
8,700 KB
testcase_33 AC 144 ms
17,748 KB
testcase_34 AC 115 ms
16,792 KB
testcase_35 AC 41 ms
8,936 KB
testcase_36 AC 60 ms
11,036 KB
testcase_37 AC 89 ms
12,896 KB
testcase_38 AC 132 ms
17,656 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 y=1,u=mod,v=0;
    while(x){
        lint q=u/x;
        u-=q*x;std::swap(x,u);
        v-=q*y;std::swap(y,v);
    }
    assert(x==0&&std::abs(y)==mod&&std::abs(u)==1&&std::abs(v)<mod);
    return v;
}
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