結果
| 問題 |
No.2214 Products on Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-22 19:22:53 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 227 ms / 3,000 ms |
| コード長 | 862 bytes |
| コンパイル時間 | 5,295 ms |
| コンパイル使用メモリ | 311,796 KB |
| 実行使用メモリ | 23,828 KB |
| 最終ジャッジ日時 | 2024-07-22 20:19:36 |
| 合計ジャッジ時間 | 12,537 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using mint = modint998244353;
int main() {
int n;
cin >> n;
vector<vector<int>> to(n);
rep(i, n-1) {
int a, b;
cin >> a >> b;
--a; --b;
to[a].push_back(b);
to[b].push_back(a);
}
vector<array<mint, 2>> dp(n);
auto dfs = [&](auto f, int v, int p=-1) -> void {
dp[v][0] = dp[v][1] = 1;
for (int u : to[v]) {
if (u == p) continue;
f(f, u, v);
mint x = dp[u][0], y = dp[u][1];
dp[v][1] = dp[v][0]*y + dp[v][1]*(x+y);
dp[v][0] *= x+y;
}
};
dfs(dfs, 0);
cout << dp[0][1].val() << '\n';
return 0;
}