結果
| 問題 |
No.827 総神童数
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-30 00:32:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 164 ms / 2,000 ms |
| コード長 | 1,222 bytes |
| コンパイル時間 | 2,260 ms |
| コンパイル使用メモリ | 199,524 KB |
| 最終ジャッジ日時 | 2025-01-09 10:56:39 |
|
ジャッジサーバー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 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';
}
ngtkana