結果

問題 No.827 総神童数
ユーザー kk
提出日時 2020-09-16 03:03:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 3,150 ms
コンパイル使用メモリ 202,040 KB
実行使用メモリ 22,868 KB
最終ジャッジ日時 2023-09-04 03:15:06
合計ジャッジ時間 9,785 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
11,972 KB
testcase_01 AC 38 ms
11,920 KB
testcase_02 AC 38 ms
12,008 KB
testcase_03 AC 39 ms
11,976 KB
testcase_04 AC 38 ms
11,944 KB
testcase_05 AC 38 ms
11,952 KB
testcase_06 AC 38 ms
12,000 KB
testcase_07 AC 37 ms
11,992 KB
testcase_08 AC 38 ms
12,056 KB
testcase_09 AC 122 ms
22,868 KB
testcase_10 AC 64 ms
15,428 KB
testcase_11 AC 40 ms
12,112 KB
testcase_12 AC 49 ms
13,688 KB
testcase_13 AC 105 ms
20,960 KB
testcase_14 AC 40 ms
12,372 KB
testcase_15 AC 64 ms
15,584 KB
testcase_16 AC 109 ms
19,196 KB
testcase_17 AC 122 ms
20,900 KB
testcase_18 AC 70 ms
16,456 KB
testcase_19 AC 135 ms
18,092 KB
testcase_20 AC 100 ms
16,512 KB
testcase_21 AC 81 ms
15,288 KB
testcase_22 AC 105 ms
16,932 KB
testcase_23 AC 39 ms
12,152 KB
testcase_24 AC 115 ms
17,424 KB
testcase_25 AC 90 ms
16,088 KB
testcase_26 AC 114 ms
17,412 KB
testcase_27 AC 85 ms
15,604 KB
testcase_28 AC 83 ms
15,596 KB
testcase_29 AC 73 ms
14,828 KB
testcase_30 AC 49 ms
12,860 KB
testcase_31 AC 66 ms
14,472 KB
testcase_32 AC 63 ms
14,168 KB
testcase_33 AC 127 ms
17,928 KB
testcase_34 AC 114 ms
17,472 KB
testcase_35 AC 65 ms
14,288 KB
testcase_36 AC 79 ms
15,200 KB
testcase_37 AC 90 ms
16,276 KB
testcase_38 AC 118 ms
17,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;
int n;
vector<int> edges[200000];
int depth[200000+1];
long long f[200000+1];
long long g[200000+1];

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

long long comb(int n, int k) {
  return f[n] * g[n-k] % MOD * g[k] % MOD;
}

void dfs(int v, int par = -1, int d = 1) {
  ++depth[d];
  for (int w: edges[v]) {
    if (w != par)
      dfs(w, v, d+1);
  }
}

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

  f[0] = g[0] = 1;
  for (int i = 1; i <= 200000; i++) {
    f[i] = i * f[i-1] % MOD;
    g[i] = modpow(f[i], MOD-2, MOD);
  }
  
  cin >> n;
  REP (i, n-1) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  dfs(0);

  long long ret = 0;
  for (int d = 1; d <= n; d++) {
    long long tmp = depth[d] * comb(n, d) % MOD * f[d-1] % MOD * f[n-d] % MOD;
    ret = (ret + tmp) % MOD;
  }
  cout << ret << endl;
  
  return 0;
}
0