結果

問題 No.2047 Path Factory
ユーザー okkuukenkenokkuukenken
提出日時 2022-08-19 23:19:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 165,040 KB
実行使用メモリ 20,736 KB
最終ジャッジ日時 2024-04-17 01:55:53
合計ジャッジ時間 4,415 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 53 ms
7,424 KB
testcase_08 AC 42 ms
6,784 KB
testcase_09 AC 47 ms
7,424 KB
testcase_10 AC 68 ms
8,832 KB
testcase_11 AC 41 ms
6,656 KB
testcase_12 AC 26 ms
5,504 KB
testcase_13 AC 27 ms
5,504 KB
testcase_14 AC 43 ms
6,784 KB
testcase_15 AC 52 ms
7,552 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 61 ms
11,960 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
#include<complex>
#include<fstream>
#include<cstdlib>
#include<functional>
#include<array>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
vector<int>G[100000];
int dp[2][100000];
void dfs(int v,int p){
	vector<array<int,2>>vec;
	for(auto&x:G[v]){
		if(x==p)
			continue;
		dfs(x,v);
		vec.push_back(array<int,2>({dp[0][x],dp[1][x]}));
	}
	vector<array<int,3>>dp2(vec.size()+1);
	dp2[0]={1,0,0};
	for(int i=0;i<vec.size();i++){
		for(int j=0;j<3;j++){
			dp2[i+1][j]=(dp2[i+1][j]+(ll)dp2[i][j]*vec[i][0])%mod;
			if(j!=2)
				dp2[i+1][j+1]=(dp2[i+1][j]+(ll)dp2[i][j]*vec[i][1])%mod;
		}
	}
	dp[0][v]=(dp2[vec.size()][1]+dp2[vec.size()][2])%mod;
	dp[1][v]=(dp2[vec.size()][0]+dp[0][v])%mod;
}
int main(){
	int n,u,v;
	cin>>n;
	while(cin>>u>>v){
		u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	cout<<dp[0][0]<<endl;
}
0