結果
問題 | No.827 総神童数 |
ユーザー | kazuma |
提出日時 | 2019-05-03 21:38:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 422 ms / 2,000 ms |
コード長 | 2,479 bytes |
コンパイル時間 | 2,321 ms |
コンパイル使用メモリ | 197,140 KB |
最終ジャッジ日時 | 2025-01-07 03:22:26 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
19,408 KB |
testcase_01 | AC | 27 ms
19,284 KB |
testcase_02 | AC | 26 ms
19,280 KB |
testcase_03 | AC | 29 ms
19,280 KB |
testcase_04 | AC | 28 ms
19,280 KB |
testcase_05 | AC | 27 ms
19,280 KB |
testcase_06 | AC | 27 ms
19,152 KB |
testcase_07 | AC | 27 ms
19,152 KB |
testcase_08 | AC | 26 ms
19,276 KB |
testcase_09 | AC | 284 ms
41,104 KB |
testcase_10 | AC | 109 ms
25,804 KB |
testcase_11 | AC | 29 ms
19,664 KB |
testcase_12 | AC | 60 ms
22,480 KB |
testcase_13 | AC | 233 ms
37,160 KB |
testcase_14 | AC | 34 ms
19,796 KB |
testcase_15 | AC | 105 ms
26,192 KB |
testcase_16 | AC | 226 ms
33,004 KB |
testcase_17 | AC | 276 ms
36,488 KB |
testcase_18 | AC | 128 ms
27,728 KB |
testcase_19 | AC | 312 ms
29,508 KB |
testcase_20 | AC | 237 ms
26,836 KB |
testcase_21 | AC | 165 ms
24,788 KB |
testcase_22 | AC | 258 ms
27,572 KB |
testcase_23 | AC | 29 ms
19,276 KB |
testcase_24 | AC | 277 ms
28,532 KB |
testcase_25 | AC | 210 ms
26,152 KB |
testcase_26 | AC | 422 ms
28,484 KB |
testcase_27 | AC | 185 ms
25,424 KB |
testcase_28 | AC | 184 ms
25,168 KB |
testcase_29 | AC | 149 ms
24,016 KB |
testcase_30 | AC | 55 ms
20,560 KB |
testcase_31 | AC | 111 ms
22,736 KB |
testcase_32 | AC | 116 ms
22,604 KB |
testcase_33 | AC | 308 ms
29,212 KB |
testcase_34 | AC | 299 ms
28,376 KB |
testcase_35 | AC | 121 ms
22,864 KB |
testcase_36 | AC | 171 ms
24,660 KB |
testcase_37 | AC | 204 ms
26,076 KB |
testcase_38 | AC | 304 ms
28,996 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using graph = vector<vector<int>>; template<int MOD> struct mod_int { static const int mod = MOD; unsigned x; mod_int() : x(0) { } mod_int(int sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } mod_int(long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } mod_int &operator+=(mod_int that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } mod_int &operator-=(mod_int that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % MOD; return *this; } mod_int &operator/=(mod_int that) { return *this *= that.inverse(); } mod_int operator+(mod_int that) const { return mod_int(*this) += that; } mod_int operator-(mod_int that) const { return mod_int(*this) -= that; } mod_int operator*(mod_int that) const { return mod_int(*this) *= that; } mod_int operator/(mod_int that) const { return mod_int(*this) /= that; } mod_int inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return mod_int(u); } }; template<int MOD> istream& operator >> (istream& is, mod_int<MOD>& val) { long long x; is >> x; val = x; return is; } template<int MOD> ostream& operator << (ostream& os, const mod_int<MOD>& val) { os << val.get(); return os; } using mint = mod_int<1000000007>; const int MAX = 2e6; bool inited = false; mint fac[MAX + 1]; mint rfac[MAX + 1]; void init() { inited = true; fac[0] = 1; for (int i = 1; i <= MAX; i++) { fac[i] = fac[i - 1] * i; } rfac[MAX] = fac[MAX].inverse(); for (int i = MAX; i >= 1; i--) { rfac[i - 1] = rfac[i] * i; } } mint nPr(int n, int r) { if (!inited) init(); return r < 0 || n < r ? 0 : fac[n] * rfac[n - r]; } mint nCr(int n, int r) { if (!inited) init(); return r < 0 || n < r ? 0 : fac[n] * rfac[n - r] * rfac[r]; } mint nHr(int n, int r) { if (!inited) init(); return r == 0 ? 1 : nCr(n + r - 1, r); } int N; mint res = 0; void dfs(int v, int prev, int d, const graph& G) { res += fac[N] / (d + 1); for (auto to : G[v]) if (to != prev) { dfs(to, v, d + 1, G); } } int main() { init(); cin >> N; graph G(N); for (int i = 0; i < N - 1; i++) { int u, v; cin >> u >> v; --u, --v; G[u].push_back(v); G[v].push_back(u); } dfs(0, -1, 0, G); cout << res << endl; return 0; }