結果

問題 No.827 総神童数
ユーザー PachicobuePachicobue
提出日時 2019-04-11 01:58:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 79,196 KB
実行使用メモリ 26,980 KB
最終ジャッジ日時 2023-09-25 15:18:54
合計ジャッジ時間 5,899 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 176 ms
26,980 KB
testcase_10 AC 56 ms
11,016 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 24 ms
6,712 KB
testcase_13 AC 133 ms
22,432 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 51 ms
11,076 KB
testcase_16 AC 133 ms
19,608 KB
testcase_17 AC 163 ms
23,212 KB
testcase_18 AC 69 ms
12,736 KB
testcase_19 AC 195 ms
19,080 KB
testcase_20 AC 134 ms
14,948 KB
testcase_21 AC 92 ms
11,796 KB
testcase_22 AC 148 ms
15,868 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 165 ms
17,176 KB
testcase_25 AC 127 ms
14,168 KB
testcase_26 AC 175 ms
17,452 KB
testcase_27 AC 106 ms
12,732 KB
testcase_28 AC 97 ms
12,444 KB
testcase_29 AC 77 ms
10,632 KB
testcase_30 AC 22 ms
5,340 KB
testcase_31 AC 58 ms
9,224 KB
testcase_32 AC 57 ms
8,884 KB
testcase_33 AC 196 ms
18,784 KB
testcase_34 AC 173 ms
17,784 KB
testcase_35 AC 60 ms
9,092 KB
testcase_36 AC 95 ms
11,536 KB
testcase_37 AC 124 ms
13,824 KB
testcase_38 AC 186 ms
18,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using ull = unsigned long long;
constexpr ull M = 1000000007;
int main()
{
    std::size_t N;
    std::cin >> N;
    std::vector<ull> L(N + 1, 1), R(N + 1, 1);
    for (std::size_t i = 1; i <= N; i++) { L[i] = L[i - 1] * (ull)(i == 1 ? 1 : i - 1) % M; }
    for (std::size_t i = N; i >= 1; i--) { R[i - 1] = R[i] * (ull)(i) % M; }
    std::vector<std::vector<std::size_t>> g(N);
    for (std::size_t i = 0; i < N - 1; i++) {
        std::size_t u, v;
        std::cin >> u >> v, u--, v--;
        g[u].push_back(v), g[v].push_back(u);
    }
    std::vector<std::size_t> dnum(N + 1, 0);
    auto dfs = [&](auto&& self, const std::size_t s, const std::size_t p, const std::size_t d) -> void {
        dnum[d]++;
        for (const std::size_t to : g[s]) {
            if (to == p) { continue; }
            self(self, to, s, d + 1);
        }
    };
    dfs(dfs, 0, N, 1);
    ull ans = 0;
    for (std::size_t d = 1; d <= N; d++) { (ans += (ull)dnum[d] * (L[d] * R[d] % M) % M) %= M; }
    std::cout << ans << std::endl;
    return 0;
}
0