結果

問題 No.827 総神童数
ユーザー coco18000coco18000
提出日時 2019-05-04 16:43:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,479 bytes
コンパイル時間 1,783 ms
コンパイル使用メモリ 172,752 KB
実行使用メモリ 17,344 KB
最終ジャッジ日時 2023-09-05 05:41:56
合計ジャッジ時間 8,927 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,236 KB
testcase_01 AC 6 ms
11,156 KB
testcase_02 AC 5 ms
11,160 KB
testcase_03 AC 6 ms
11,304 KB
testcase_04 AC 6 ms
11,160 KB
testcase_05 AC 6 ms
11,188 KB
testcase_06 AC 5 ms
11,196 KB
testcase_07 AC 5 ms
11,192 KB
testcase_08 AC 6 ms
11,376 KB
testcase_09 AC 211 ms
17,340 KB
testcase_10 AC 71 ms
13,408 KB
testcase_11 AC 8 ms
11,464 KB
testcase_12 AC 32 ms
12,324 KB
testcase_13 AC 165 ms
16,124 KB
testcase_14 AC 11 ms
11,468 KB
testcase_15 AC 65 ms
13,168 KB
testcase_16 AC 162 ms
16,124 KB
testcase_17 AC 197 ms
17,032 KB
testcase_18 AC 85 ms
13,868 KB
testcase_19 AC 229 ms
17,344 KB
testcase_20 AC 162 ms
15,928 KB
testcase_21 AC 114 ms
14,572 KB
testcase_22 AC 176 ms
16,124 KB
testcase_23 AC 6 ms
11,196 KB
testcase_24 AC 198 ms
16,792 KB
testcase_25 AC 147 ms
15,432 KB
testcase_26 AC 202 ms
16,744 KB
testcase_27 AC 131 ms
14,940 KB
testcase_28 AC 126 ms
14,828 KB
testcase_29 AC 100 ms
14,136 KB
testcase_30 AC 31 ms
12,116 KB
testcase_31 AC 77 ms
13,788 KB
testcase_32 AC 75 ms
13,388 KB
testcase_33 AC 225 ms
17,164 KB
testcase_34 AC 203 ms
16,656 KB
testcase_35 AC 80 ms
13,464 KB
testcase_36 AC 112 ms
14,772 KB
testcase_37 AC 149 ms
15,636 KB
testcase_38 AC 217 ms
17,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> n;
    ll depth = INF;
};

Vertex V[200005];
ll F;
ll IF[200005];
ll N;

int main()
{
    cin >> N;
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].n.push_back(b);
        V[b].n.push_back(a);
    }

    queue<pll> q;
    q.push(pll(0, 0));
    while (!q.empty())
    {
        pll t = q.front();
        q.pop();
        V[t.first].depth = t.second;
        int nd = t.second + 1;
        REP(i, V[t.first].n.size())
        {
            int n = V[t.first].n[i];
            if (nd >= V[n].depth)
                continue;
            q.push(pll(n, nd));
        }
    }
    memset(IF, 0, sizeof(IF));
    FOR(i, N + 2, 1)
    {
        ll f = 1;
        ll t = i;
        for (int j = 0; j <= 30; ++j)
        {
            if ((((MOD - 2) >> j) & 1) == 1)
            {
                f *= t;
                f %= MOD;
            }
            t = (t * t) % MOD;
        }
        IF[i] = f;
    }
    F = 1;
    FOR(i, N + 1, 1)
    {
        F = F * i % MOD;
    }
    ll ans = 0;
    REP(i, N)
    {
        ans += F * IF[V[i].depth + 1];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}
0