結果

問題 No.2214 Products on Tree
ユーザー 沙耶花沙耶花
提出日時 2023-02-10 22:03:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 3,000 ms
コード長 758 bytes
コンパイル時間 4,665 ms
コンパイル使用メモリ 260,984 KB
実行使用メモリ 31,332 KB
最終ジャッジ日時 2023-09-21 23:18:33
合計ジャッジ時間 9,600 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,024 KB
testcase_01 AC 3 ms
5,012 KB
testcase_02 AC 3 ms
5,216 KB
testcase_03 AC 160 ms
15,020 KB
testcase_04 AC 165 ms
15,408 KB
testcase_05 AC 156 ms
14,948 KB
testcase_06 AC 105 ms
11,860 KB
testcase_07 AC 31 ms
6,836 KB
testcase_08 AC 20 ms
5,876 KB
testcase_09 AC 39 ms
7,244 KB
testcase_10 AC 99 ms
11,552 KB
testcase_11 AC 51 ms
8,136 KB
testcase_12 AC 61 ms
8,816 KB
testcase_13 AC 177 ms
15,680 KB
testcase_14 AC 178 ms
15,620 KB
testcase_15 AC 177 ms
15,648 KB
testcase_16 AC 177 ms
15,720 KB
testcase_17 AC 178 ms
15,612 KB
testcase_18 AC 85 ms
13,068 KB
testcase_19 AC 92 ms
13,524 KB
testcase_20 AC 83 ms
12,780 KB
testcase_21 AC 64 ms
10,928 KB
testcase_22 AC 116 ms
16,292 KB
testcase_23 AC 3 ms
4,888 KB
testcase_24 AC 2 ms
4,892 KB
testcase_25 AC 3 ms
4,912 KB
testcase_26 AC 3 ms
4,916 KB
testcase_27 AC 3 ms
4,872 KB
testcase_28 AC 111 ms
23,880 KB
testcase_29 AC 28 ms
7,404 KB
testcase_30 AC 108 ms
16,364 KB
testcase_31 AC 151 ms
16,308 KB
testcase_32 AC 125 ms
16,448 KB
testcase_33 AC 151 ms
31,332 KB
testcase_34 AC 154 ms
31,208 KB
testcase_35 AC 160 ms
23,588 KB
testcase_36 AC 163 ms
23,232 KB
testcase_37 AC 136 ms
15,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

mint dp[200005][2];
vector<vector<int>> E;

void dfs(int c,int p){
	dp[c][0] = 1;
	rep(i,E[c].size()){
		int to = E[c][i];
		if(to==p)continue;
		dfs(to,c);
		mint x = dp[to][0],y = dp[to][1];
		dp[c][1] = dp[c][0] * y + dp[c][1] * (x + (y));
		dp[c][0] = dp[c][0]*x + dp[c][0]*y;
	}
	dp[c][1] += dp[c][0];
}

int main(){
	int n;
	cin>>n;
	E.resize(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	
	dfs(0,-1);
	
	cout<<dp[0][1].val()<<endl;
	
	
	return 0;
}
0