結果

問題 No.2214 Products on Tree
ユーザー maksimmaksim
提出日時 2023-02-10 21:44:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 156 ms / 3,000 ms
コード長 786 bytes
コンパイル時間 1,848 ms
コンパイル使用メモリ 166,252 KB
実行使用メモリ 27,244 KB
最終ジャッジ日時 2023-09-21 22:51:57
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,012 KB
testcase_01 AC 4 ms
8,308 KB
testcase_02 AC 4 ms
7,996 KB
testcase_03 AC 147 ms
18,340 KB
testcase_04 AC 153 ms
18,444 KB
testcase_05 AC 142 ms
17,764 KB
testcase_06 AC 90 ms
15,144 KB
testcase_07 AC 21 ms
10,144 KB
testcase_08 AC 14 ms
9,536 KB
testcase_09 AC 27 ms
10,700 KB
testcase_10 AC 84 ms
14,640 KB
testcase_11 AC 36 ms
11,740 KB
testcase_12 AC 46 ms
12,444 KB
testcase_13 AC 156 ms
18,840 KB
testcase_14 AC 156 ms
18,676 KB
testcase_15 AC 155 ms
18,636 KB
testcase_16 AC 155 ms
18,644 KB
testcase_17 AC 156 ms
18,604 KB
testcase_18 AC 65 ms
15,808 KB
testcase_19 AC 69 ms
16,408 KB
testcase_20 AC 59 ms
15,884 KB
testcase_21 AC 44 ms
14,232 KB
testcase_22 AC 78 ms
18,580 KB
testcase_23 AC 4 ms
8,060 KB
testcase_24 AC 5 ms
8,088 KB
testcase_25 AC 5 ms
8,016 KB
testcase_26 AC 4 ms
8,112 KB
testcase_27 AC 4 ms
8,140 KB
testcase_28 AC 54 ms
22,180 KB
testcase_29 AC 18 ms
10,540 KB
testcase_30 AC 55 ms
18,796 KB
testcase_31 AC 93 ms
18,952 KB
testcase_32 AC 82 ms
18,760 KB
testcase_33 AC 72 ms
27,244 KB
testcase_34 AC 72 ms
26,992 KB
testcase_35 AC 109 ms
23,252 KB
testcase_36 AC 109 ms
23,172 KB
testcase_37 AC 68 ms
19,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0