結果

問題 No.2047 Path Factory
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 21:54:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 72,504 KB
実行使用メモリ 20,680 KB
最終ジャッジ日時 2024-04-23 13:30:08
合計ジャッジ時間 2,924 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,192 KB
testcase_01 AC 4 ms
8,064 KB
testcase_02 AC 5 ms
8,076 KB
testcase_03 AC 4 ms
8,192 KB
testcase_04 AC 5 ms
8,192 KB
testcase_05 AC 4 ms
8,128 KB
testcase_06 AC 5 ms
8,320 KB
testcase_07 AC 59 ms
10,112 KB
testcase_08 AC 48 ms
9,792 KB
testcase_09 AC 55 ms
10,168 KB
testcase_10 AC 80 ms
10,820 KB
testcase_11 AC 47 ms
9,728 KB
testcase_12 AC 27 ms
9,160 KB
testcase_13 AC 28 ms
9,216 KB
testcase_14 AC 52 ms
9,728 KB
testcase_15 AC 59 ms
10,180 KB
testcase_16 AC 44 ms
10,312 KB
testcase_17 AC 43 ms
10,180 KB
testcase_18 AC 50 ms
11,076 KB
testcase_19 AC 61 ms
11,776 KB
testcase_20 AC 96 ms
13,512 KB
testcase_21 AC 47 ms
10,820 KB
testcase_22 AC 12 ms
8,832 KB
testcase_23 AC 16 ms
9,024 KB
testcase_24 AC 14 ms
8,704 KB
testcase_25 AC 81 ms
20,680 KB
testcase_26 AC 112 ms
18,432 KB
testcase_27 AC 92 ms
11,392 KB
testcase_28 AC 58 ms
11,336 KB
testcase_29 AC 4 ms
8,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N;
vector<int>G[1<<17];
mint dp[1<<17][3];
void dfs(int u,int p)
{
	mint a=1,b=0,c=0;
	for(int v:G[u])if(v!=p)
	{
		dfs(v,u);
		mint na=a*(dp[v][0]+dp[v][1]);
		mint nb=b*(dp[v][0]+dp[v][1])+a*(dp[v][1]+dp[v][2]);
		mint nc=c*(dp[v][0]+dp[v][1])+b*(dp[v][1]+dp[v][2]);
		a=na,b=nb,c=nc;
	}
	dp[u][0]=c;
	dp[u][1]=b;
	dp[u][2]=a;
}
int main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0);
	cout<<(dp[1][0]+dp[1][1]).val()<<endl;
}
0