結果
問題 | No.827 総神童数 |
ユーザー | kazuma |
提出日時 | 2019-05-03 21:38:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 265 ms / 2,000 ms |
コード長 | 2,479 bytes |
コンパイル時間 | 2,039 ms |
コンパイル使用メモリ | 202,736 KB |
実行使用メモリ | 40,860 KB |
最終ジャッジ日時 | 2023-08-30 06:00:41 |
合計ジャッジ時間 | 9,055 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
19,048 KB |
testcase_01 | AC | 25 ms
18,992 KB |
testcase_02 | AC | 26 ms
18,944 KB |
testcase_03 | AC | 26 ms
19,112 KB |
testcase_04 | AC | 26 ms
19,064 KB |
testcase_05 | AC | 26 ms
18,996 KB |
testcase_06 | AC | 26 ms
18,988 KB |
testcase_07 | AC | 25 ms
19,064 KB |
testcase_08 | AC | 26 ms
19,052 KB |
testcase_09 | AC | 242 ms
40,860 KB |
testcase_10 | AC | 96 ms
25,620 KB |
testcase_11 | AC | 28 ms
19,340 KB |
testcase_12 | AC | 53 ms
22,296 KB |
testcase_13 | AC | 195 ms
36,844 KB |
testcase_14 | AC | 31 ms
19,596 KB |
testcase_15 | AC | 90 ms
25,832 KB |
testcase_16 | AC | 193 ms
32,988 KB |
testcase_17 | AC | 228 ms
36,508 KB |
testcase_18 | AC | 110 ms
27,468 KB |
testcase_19 | AC | 265 ms
29,436 KB |
testcase_20 | AC | 196 ms
26,868 KB |
testcase_21 | AC | 144 ms
24,828 KB |
testcase_22 | AC | 216 ms
27,348 KB |
testcase_23 | AC | 27 ms
19,012 KB |
testcase_24 | AC | 235 ms
28,184 KB |
testcase_25 | AC | 181 ms
25,888 KB |
testcase_26 | AC | 236 ms
28,136 KB |
testcase_27 | AC | 158 ms
25,132 KB |
testcase_28 | AC | 156 ms
25,040 KB |
testcase_29 | AC | 128 ms
24,056 KB |
testcase_30 | AC | 50 ms
20,332 KB |
testcase_31 | AC | 101 ms
22,812 KB |
testcase_32 | AC | 100 ms
22,448 KB |
testcase_33 | AC | 259 ms
29,048 KB |
testcase_34 | AC | 239 ms
28,312 KB |
testcase_35 | AC | 103 ms
22,668 KB |
testcase_36 | AC | 139 ms
24,284 KB |
testcase_37 | AC | 180 ms
25,880 KB |
testcase_38 | AC | 255 ms
29,248 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; }