結果

問題 No.827 総神童数
ユーザー pekempeypekempey
提出日時 2019-05-03 21:37:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,325 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 73,888 KB
実行使用メモリ 25,140 KB
最終ジャッジ日時 2023-08-30 05:58:35
合計ジャッジ時間 6,259 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,460 KB
testcase_01 AC 7 ms
10,380 KB
testcase_02 AC 7 ms
10,496 KB
testcase_03 AC 7 ms
10,448 KB
testcase_04 AC 7 ms
10,380 KB
testcase_05 AC 8 ms
10,472 KB
testcase_06 AC 7 ms
10,432 KB
testcase_07 AC 7 ms
10,468 KB
testcase_08 AC 8 ms
10,376 KB
testcase_09 AC 177 ms
25,140 KB
testcase_10 AC 62 ms
15,000 KB
testcase_11 AC 9 ms
10,824 KB
testcase_12 AC 30 ms
12,696 KB
testcase_13 AC 136 ms
22,636 KB
testcase_14 AC 12 ms
11,060 KB
testcase_15 AC 57 ms
15,212 KB
testcase_16 AC 143 ms
19,524 KB
testcase_17 AC 169 ms
21,768 KB
testcase_18 AC 75 ms
16,300 KB
testcase_19 AC 201 ms
16,652 KB
testcase_20 AC 141 ms
14,944 KB
testcase_21 AC 96 ms
13,728 KB
testcase_22 AC 148 ms
15,488 KB
testcase_23 AC 8 ms
10,508 KB
testcase_24 AC 167 ms
15,856 KB
testcase_25 AC 127 ms
14,612 KB
testcase_26 AC 169 ms
15,944 KB
testcase_27 AC 104 ms
14,060 KB
testcase_28 AC 101 ms
14,020 KB
testcase_29 AC 81 ms
13,304 KB
testcase_30 AC 28 ms
11,284 KB
testcase_31 AC 62 ms
12,964 KB
testcase_32 AC 60 ms
12,580 KB
testcase_33 AC 181 ms
16,376 KB
testcase_34 AC 163 ms
15,912 KB
testcase_35 AC 61 ms
12,680 KB
testcase_36 AC 86 ms
13,648 KB
testcase_37 AC 115 ms
14,756 KB
testcase_38 AC 178 ms
16,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

mint F[200001] = {1, 1};
mint R[200001] = {1, 1};
mint I[200001] = {0, 1};

mint C(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return F[n] * R[n - r] * R[r];
}

void init() {
  for (int i = 2; i <= 200000; i++) {
    I[i] = I[MOD % i] * (MOD - MOD / i);
    F[i] = F[i - 1] * i;
    R[i] = R[i - 1] * I[i];
  }
}

int N;
vector<int> G[200000];
mint ans;

void dfs(int u, int p, int d) {
  ans += F[N] * I[d + 1];
  for (int v : G[u]) if (v != p) {
    dfs(v, u, d + 1);
  }
}

int main() {
  init();
  cin >> N;
  REP(i, N-1) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(0, -1, 0);
  cout << ans.n << '\n';
}
0