結果

問題 No.828 全方位神童数
コンテスト
ユーザー 梧桐
提出日時 2026-02-23 20:04:55
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,036 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 608 ms
コンパイル使用メモリ 75,588 KB
実行使用メモリ 8,156 KB
最終ジャッジ日時 2026-02-23 20:05:12
合計ジャッジ時間 14,697 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 8 TLE * 3 -- * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef long long LL;

const int N = 200010, M = 2 * N, MOD = 1000000007;

int n, r[N], h[N], e[M], ne[M], idx, s[N];
LL ans;

void Add(int x, int y) {
    e[idx] = y, ne[idx] = h[x], h[x] = idx++;
}

void DFS(int u, int p, int ma, int id) {
    for (int i = h[u]; i != -1; i = ne[i]) {
        int v = e[i];
        if (v == p) continue;
        if (v > ma) ++s[id];
        DFS(v, u, max(ma, v), id);
    }
}

int main() {
    // freopen("prodigy.in", "r", stdin);
    // freopen("prodigy.out", "w", stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &r[i]);
    memset(h, -1, sizeof(h));
    for (int i = 1, u, v; i <= n - 1; ++i) {
        scanf("%d%d", &u, &v);
        Add(u, v), Add(v, u);
    }

    for (int i = 1; i <= n; ++i) {
        s[i] = 1;
        DFS(i, 0, i, i);
    }

    ans = 1LL;
    for (int i = 1; i <= n; ++i) {
        ans = ans * (r[i] + s[i]) % MOD;
    }

    printf("%lld\n", ans);

    return 0;
}
0