結果

問題 No.2214 Products on Tree
ユーザー V_MelvilleV_Melville
提出日時 2023-02-22 19:22:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 3,000 ms
コード長 862 bytes
コンパイル時間 6,114 ms
コンパイル使用メモリ 311,008 KB
実行使用メモリ 23,828 KB
最終ジャッジ日時 2023-09-30 02:25:26
合計ジャッジ時間 14,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 183 ms
15,048 KB
testcase_04 AC 189 ms
15,456 KB
testcase_05 AC 169 ms
14,588 KB
testcase_06 AC 113 ms
11,472 KB
testcase_07 AC 29 ms
5,460 KB
testcase_08 AC 19 ms
4,564 KB
testcase_09 AC 37 ms
6,200 KB
testcase_10 AC 99 ms
10,680 KB
testcase_11 AC 50 ms
7,108 KB
testcase_12 AC 61 ms
8,164 KB
testcase_13 AC 186 ms
15,564 KB
testcase_14 AC 196 ms
15,636 KB
testcase_15 AC 188 ms
15,696 KB
testcase_16 AC 185 ms
15,596 KB
testcase_17 AC 195 ms
15,596 KB
testcase_18 AC 90 ms
12,540 KB
testcase_19 AC 98 ms
13,260 KB
testcase_20 AC 85 ms
12,232 KB
testcase_21 AC 64 ms
10,356 KB
testcase_22 AC 126 ms
16,116 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,360 KB
testcase_26 AC 1 ms
4,356 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 104 ms
18,136 KB
testcase_29 AC 28 ms
5,988 KB
testcase_30 AC 106 ms
16,448 KB
testcase_31 AC 162 ms
16,444 KB
testcase_32 AC 129 ms
16,460 KB
testcase_33 AC 143 ms
23,828 KB
testcase_34 AC 142 ms
23,604 KB
testcase_35 AC 168 ms
19,600 KB
testcase_36 AC 168 ms
19,624 KB
testcase_37 AC 133 ms
15,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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