結果

問題 No.827 総神童数
ユーザー 👑 emthrmemthrm
提出日時 2019-05-04 16:57:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 1,747 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 124,152 KB
実行使用メモリ 20,656 KB
最終ジャッジ日時 2023-09-05 06:05:08
合計ジャッジ時間 6,694 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,000 KB
testcase_01 AC 4 ms
8,336 KB
testcase_02 AC 4 ms
8,072 KB
testcase_03 AC 4 ms
8,008 KB
testcase_04 AC 4 ms
8,016 KB
testcase_05 AC 4 ms
8,096 KB
testcase_06 AC 4 ms
8,120 KB
testcase_07 AC 4 ms
8,068 KB
testcase_08 AC 4 ms
8,148 KB
testcase_09 AC 181 ms
20,656 KB
testcase_10 AC 57 ms
12,112 KB
testcase_11 AC 7 ms
8,216 KB
testcase_12 AC 25 ms
9,992 KB
testcase_13 AC 140 ms
18,512 KB
testcase_14 AC 8 ms
8,488 KB
testcase_15 AC 55 ms
12,172 KB
testcase_16 AC 142 ms
16,452 KB
testcase_17 AC 167 ms
18,392 KB
testcase_18 AC 68 ms
13,188 KB
testcase_19 AC 162 ms
15,016 KB
testcase_20 AC 112 ms
13,092 KB
testcase_21 AC 74 ms
11,796 KB
testcase_22 AC 123 ms
13,616 KB
testcase_23 AC 5 ms
8,056 KB
testcase_24 AC 133 ms
14,176 KB
testcase_25 AC 100 ms
12,776 KB
testcase_26 AC 140 ms
14,272 KB
testcase_27 AC 86 ms
12,356 KB
testcase_28 AC 85 ms
12,140 KB
testcase_29 AC 65 ms
11,284 KB
testcase_30 AC 21 ms
9,060 KB
testcase_31 AC 51 ms
10,556 KB
testcase_32 AC 47 ms
10,556 KB
testcase_33 AC 152 ms
14,732 KB
testcase_34 AC 141 ms
14,204 KB
testcase_35 AC 49 ms
10,632 KB
testcase_36 AC 71 ms
11,696 KB
testcase_37 AC 95 ms
12,684 KB
testcase_38 AC 151 ms
14,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int cnt[200000] = {};
vector<int> edge[200000];
void dfs(int ver) {
  for (int e : edge[ver]) if (cnt[e] == 0) {
    cnt[e] = cnt[ver] + 1;
    dfs(e);
  }
}

long long mod_inv(long long a, long long mod = MOD) {
  a %= mod;
  if (__gcd(a, mod) != 1) return -1;
  long long b = mod, x = 1, y = 0;
  while (b > 0) {
    long long tmp = a / b;
    a -= tmp * b;
    swap(a, b);
    x -= tmp * y;
    swap(x, y);
  }
  x %= mod;
  if (x < 0) x += mod;
  return x;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  REP(i, n - 1) {
    int u, v; cin >> u >> v; --u; --v;
    edge[u].emplace_back(v);
    edge[v].emplace_back(u);
  }
  cnt[0] = 1;
  dfs(0);
  long long ans = 0;
  REP(i, n) (ans += mod_inv(cnt[i])) %= MOD;
  FOR(i, 1, n + 1) (ans *= i) %= MOD;
  cout << ans << '\n';
  return 0;
}
0