結果

問題 No.828 全方位神童数
コンテスト
ユーザー Pachicobue
提出日時 2019-04-11 19:58:42
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,182 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,402 ms
コンパイル使用メモリ 90,780 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2026-06-07 10:21:22
合計ジャッジ時間 9,552 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 TLE * 1 -- * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <iostream>
#include <vector>
#include <algorithm>
using ull = unsigned long long;
constexpr ull MOD = 1000000007;
int main()
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::size_t N;
    std::cin >> N;
    std::vector<ull> R(N);
    for (std::size_t i = 0; i < N; i++) { std::cin >> R[i]; }
    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> sindo(N, 0);
    auto dfs = [&](auto&& self, const std::size_t s, const std::size_t p, const std::size_t R) -> void {
        sindo[s]++;
        for (const std::size_t to : g[s]) {
            if (to == p) { continue; }
            if (to >= R) { continue; }
            self(self, to, s, R);
        }
    };

    for (std::size_t i = 0; i < N; i++) { dfs(dfs, i, N, i); }
    ull ans = 1;
    for (std::size_t i = 0; i < N; i++) { (ans *= (sindo[i] + R[i]) % MOD) %= MOD; }
    std::cout << ans << std::endl;
    return 0;
}
0