結果
| 問題 |
No.827 総神童数
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-30 00:14:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 208 ms / 2,000 ms |
| コード長 | 1,214 bytes |
| コンパイル時間 | 2,535 ms |
| コンパイル使用メモリ | 198,288 KB |
| 最終ジャッジ日時 | 2025-01-09 10:55:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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 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';
}
ngtkana