結果
| 問題 |
No.2214 Products on Tree
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-10 21:44:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 89 ms / 3,000 ms |
| コード長 | 786 bytes |
| コンパイル時間 | 1,373 ms |
| コンパイル使用メモリ | 170,336 KB |
| 実行使用メモリ | 30,080 KB |
| 最終ジャッジ日時 | 2024-07-07 15:56:54 |
| 合計ジャッジ時間 | 4,477 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int p=998244353;
const int maxn=2e5+5;
vector<int> a[maxn];
bool used[maxn];
int dp[maxn][2];
void dfs(int x)
{
used[x]=true;
dp[x][0]=1;dp[x][1]=1;
for(int v:a[x])
{
if(!used[v])
{
dfs(v);
dp[x][1]=(dp[x][0]*dp[v][1]+dp[x][1]*dp[v][0]+dp[x][1]*dp[v][1]);
dp[x][1]%=p;
dp[x][0]=(dp[x][0]*dp[v][0]+dp[x][0]*dp[v][1]);
dp[x][0]%=p;
}
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;cin>>n;
for(int i=0;i<n-1;++i)
{
int x,y;cin>>x>>y;--x;--y;
a[x].push_back(y);a[y].push_back(x);
}
dfs(0);
cout<<(dp[0][1]%p+p)%p;
return 0;
}