結果

問題 No.827 総神童数
ユーザー DAyamaCTFDAyamaCTF
提出日時 2019-05-11 08:49:34
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,400 bytes
コンパイル時間 1,535 ms
コンパイル使用メモリ 147,740 KB
実行使用メモリ 28,804 KB
最終ジャッジ日時 2023-09-14 18:06:16
合計ジャッジ時間 7,972 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
11,236 KB
testcase_01 AC 32 ms
11,364 KB
testcase_02 AC 33 ms
11,180 KB
testcase_03 AC 32 ms
11,216 KB
testcase_04 AC 33 ms
11,244 KB
testcase_05 AC 33 ms
11,188 KB
testcase_06 AC 33 ms
11,176 KB
testcase_07 AC 32 ms
11,168 KB
testcase_08 AC 33 ms
11,172 KB
testcase_09 AC 142 ms
28,804 KB
testcase_10 AC 64 ms
16,556 KB
testcase_11 AC 34 ms
11,572 KB
testcase_12 AC 45 ms
14,060 KB
testcase_13 AC 117 ms
25,860 KB
testcase_14 AC 36 ms
11,832 KB
testcase_15 AC 63 ms
16,948 KB
testcase_16 AC 119 ms
21,728 KB
testcase_17 AC 137 ms
24,384 KB
testcase_18 AC 73 ms
18,200 KB
testcase_19 AC 185 ms
18,368 KB
testcase_20 AC 131 ms
16,440 KB
testcase_21 AC 96 ms
15,044 KB
testcase_22 AC 139 ms
16,868 KB
testcase_23 AC 33 ms
11,360 KB
testcase_24 AC 158 ms
17,512 KB
testcase_25 AC 121 ms
16,020 KB
testcase_26 AC 158 ms
17,492 KB
testcase_27 AC 103 ms
15,400 KB
testcase_28 AC 102 ms
15,448 KB
testcase_29 AC 78 ms
14,568 KB
testcase_30 AC 44 ms
12,276 KB
testcase_31 AC 68 ms
13,800 KB
testcase_32 AC 64 ms
13,684 KB
testcase_33 AC 162 ms
18,220 KB
testcase_34 AC 150 ms
17,540 KB
testcase_35 AC 68 ms
13,828 KB
testcase_36 AC 88 ms
14,988 KB
testcase_37 AC 114 ms
16,024 KB
testcase_38 AC 164 ms
17,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll fac[200010],finv[200010];
ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  else return (fac[n]*finv[n-r]%mod)*finv[r]%mod;
}

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll n;
vector<ll> g[200010];
ll res=0;

void dfs(ll v,ll pre,ll d){
  for(ll nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v,d+1);
  }
  ll add=fac[d]*comb(n,d+1)%mod;
  add*=fac[n-1-d]; add%=mod;
  res+=add; res%=mod;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  fac[0]=1;
  rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>n;
  rep(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0,-1,0);

  cout<<res<<endl;

  return 0;
}
0