結果
問題 |
No.827 総神童数
|
ユーザー |
![]() |
提出日時 | 2020-03-30 00:37:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 560 ms / 2,000 ms |
コード長 | 1,124 bytes |
コンパイル時間 | 3,297 ms |
コンパイル使用メモリ | 197,980 KB |
最終ジャッジ日時 | 2025-01-09 10:56:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 |
ソースコード
#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'; }