結果

問題 No.2214 Products on Tree
ユーザー otoshigootoshigo
提出日時 2023-02-11 11:04:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,258 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 207,544 KB
実行使用メモリ 62,440 KB
最終ジャッジ日時 2023-09-22 09:31:32
合計ジャッジ時間 8,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 25 ms
7,200 KB
testcase_08 AC 16 ms
5,764 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 51 ms
11,500 KB
testcase_13 AC 174 ms
25,052 KB
testcase_14 WA -
testcase_15 AC 169 ms
24,960 KB
testcase_16 AC 165 ms
25,088 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 137 ms
31,932 KB
testcase_32 WA -
testcase_33 AC 127 ms
62,440 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll MOD=998244353;

void dfs(int x,int p,vector<vector<int>>&g,vector<vector<ll>>&dp){
    vector<ll>A,B;
    for(auto i:g[x]){
        if(i==p)continue;
        dfs(i,x,g,dp);
        A.push_back(dp[i][1]);
        B.push_back(dp[i][0]);
    }
    int l=A.size();
    vector<ll>L(l+1),R(l+1);
    L[0]=R[l]=1;
    rep(i,l)L[i+1]=L[i]*(A[i]+B[i])%MOD;
    rrep(i,l)R[i]=R[i+1]*(A[i]+B[i])%MOD;
    dp[x][0]=dp[x][1]=L[l];
    rep(i,l){
        dp[x][1]+=A[i]*(L[i]*R[i+1]%MOD)%MOD;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<vector<int>>g(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<vector<ll>>dp(n,vector<ll>(2));
    dfs(0,-1,g,dp);
    ll ans=dp[0][1];
    cout<<ans<<"\n";
}
0