結果

問題 No.2047 Path Factory
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 21:54:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 623 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 73,796 KB
実行使用メモリ 18,916 KB
最終ジャッジ日時 2023-08-05 16:22:53
合計ジャッジ時間 3,226 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,984 KB
testcase_01 AC 5 ms
7,972 KB
testcase_02 AC 5 ms
7,964 KB
testcase_03 AC 4 ms
7,984 KB
testcase_04 AC 5 ms
8,084 KB
testcase_05 AC 4 ms
8,264 KB
testcase_06 AC 4 ms
8,036 KB
testcase_07 AC 56 ms
10,064 KB
testcase_08 AC 47 ms
9,580 KB
testcase_09 AC 55 ms
9,880 KB
testcase_10 AC 78 ms
10,640 KB
testcase_11 AC 44 ms
9,656 KB
testcase_12 AC 27 ms
8,944 KB
testcase_13 AC 28 ms
8,992 KB
testcase_14 AC 48 ms
9,664 KB
testcase_15 AC 59 ms
10,020 KB
testcase_16 AC 41 ms
10,384 KB
testcase_17 AC 42 ms
10,008 KB
testcase_18 AC 51 ms
10,676 KB
testcase_19 AC 64 ms
11,520 KB
testcase_20 AC 97 ms
12,880 KB
testcase_21 AC 52 ms
10,596 KB
testcase_22 AC 12 ms
8,620 KB
testcase_23 AC 15 ms
8,848 KB
testcase_24 AC 13 ms
8,584 KB
testcase_25 AC 74 ms
18,916 KB
testcase_26 AC 111 ms
17,036 KB
testcase_27 AC 92 ms
11,148 KB
testcase_28 AC 54 ms
11,208 KB
testcase_29 AC 4 ms
8,060 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