結果
| 問題 |
No.2214 Products on Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-02 19:27:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 143 ms / 3,000 ms |
| コード長 | 592 bytes |
| コンパイル時間 | 2,280 ms |
| コンパイル使用メモリ | 194,240 KB |
| 実行使用メモリ | 33,408 KB |
| 最終ジャッジ日時 | 2025-06-02 19:27:30 |
| 合計ジャッジ時間 | 7,859 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d%d", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using LL = long long;
const int N = 2e5 + 7;
const int MOD = 998244353;
std::vector<int> e[N];
LL f[N], g[N];
int n;
void dp(int x, int y) {
f[x] = g[x] = 1;
for(int v: e[x])
if(v != y) {
dp(v, x);
LL tf = f[x], tg = g[x];
f[x] = (tf * f[v] + tf * g[v] + tg * f[v]) % MOD;
g[x] = (tg * f[v] + tg * g[v]) % MOD;
}
}
int main() {
scanf("%d", &n);
for(int i = 1, x, y; i < n; ++i) {
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
dp(1, -1);
printf("%lld\n", f[1]);
return 0;
}