結果

問題 No.2047 Path Factory
ユーザー 沙耶花沙耶花
提出日時 2022-08-19 21:54:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 904 bytes
コンパイル時間 4,837 ms
コンパイル使用メモリ 263,312 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-23 13:29:51
合計ジャッジ時間 6,673 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 66 ms
10,112 KB
testcase_08 AC 47 ms
8,704 KB
testcase_09 AC 52 ms
9,856 KB
testcase_10 AC 73 ms
12,288 KB
testcase_11 AC 43 ms
8,704 KB
testcase_12 AC 26 ms
6,944 KB
testcase_13 AC 27 ms
6,944 KB
testcase_14 AC 47 ms
9,088 KB
testcase_15 AC 55 ms
10,368 KB
testcase_16 AC 39 ms
9,216 KB
testcase_17 AC 38 ms
9,088 KB
testcase_18 AC 48 ms
10,752 KB
testcase_19 AC 57 ms
12,544 KB
testcase_20 AC 85 ms
16,384 KB
testcase_21 AC 45 ms
10,368 KB
testcase_22 AC 10 ms
6,944 KB
testcase_23 AC 13 ms
6,944 KB
testcase_24 AC 12 ms
6,944 KB
testcase_25 AC 85 ms
26,624 KB
testcase_26 AC 107 ms
23,552 KB
testcase_27 AC 87 ms
14,464 KB
testcase_28 AC 61 ms
14,580 KB
testcase_29 AC 2 ms
6,948 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 4000000000000000001
int n;
vector<vector<int>> E;
vector<vector<mint>> dp;

void dfs(int cur,int p){
	vector<mint> tdp(3,0);
	tdp[0] = 1;
	rep(i,E[cur].size()){
		int to = E[cur][i];
		if(to==p)continue;
		dfs(to,cur);
		vector<mint> ndp(3,0);
		rep(j,3){
			ndp[j] += tdp[j] * dp[to][1];
			if(j!=2){
				ndp[j+1] += tdp[j] * dp[to][0];
			}
		}
		swap(tdp,ndp);
	}
	
	dp[cur][0] = tdp[0] + tdp[1];
	dp[cur][1] = tdp[1] + tdp[2];
	
}

int main() {	
	cin>>n;
	E.resize(n);
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		u--,v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dp.resize(n,vector<mint>(2,0));
	dfs(0,-1);
	mint ans = dp[0][1];
	
	cout<<ans.val()<<endl;
    return 0;
}
0