結果
| 問題 |
No.828 全方位神童数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-11 19:58:42 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,182 bytes |
| コンパイル時間 | 4,246 ms |
| コンパイル使用メモリ | 115,872 KB |
| 最終ジャッジ日時 | 2025-01-07 01:40:03 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 TLE * 21 |
ソースコード
#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;
}