結果

問題 No.2047 Path Factory
ユーザー CleverLarry0702CleverLarry0702
提出日時 2022-12-01 13:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 606 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 168,728 KB
実行使用メモリ 21,988 KB
最終ジャッジ日時 2023-07-30 02:06:16
合計ジャッジ時間 5,920 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,760 KB
testcase_01 AC 3 ms
7,712 KB
testcase_02 AC 3 ms
7,748 KB
testcase_03 AC 3 ms
7,444 KB
testcase_04 AC 3 ms
7,476 KB
testcase_05 AC 3 ms
7,440 KB
testcase_06 AC 3 ms
7,488 KB
testcase_07 AC 60 ms
11,248 KB
testcase_08 AC 46 ms
10,484 KB
testcase_09 AC 54 ms
11,072 KB
testcase_10 AC 79 ms
12,512 KB
testcase_11 AC 44 ms
10,452 KB
testcase_12 AC 26 ms
9,324 KB
testcase_13 AC 28 ms
9,360 KB
testcase_14 AC 49 ms
10,672 KB
testcase_15 AC 60 ms
11,288 KB
testcase_16 AC 41 ms
10,844 KB
testcase_17 AC 43 ms
10,632 KB
testcase_18 AC 54 ms
11,700 KB
testcase_19 AC 66 ms
12,540 KB
testcase_20 AC 100 ms
14,860 KB
testcase_21 AC 53 ms
11,312 KB
testcase_22 AC 11 ms
8,472 KB
testcase_23 AC 14 ms
8,696 KB
testcase_24 AC 12 ms
8,504 KB
testcase_25 AC 77 ms
21,988 KB
testcase_26 AC 119 ms
19,668 KB
testcase_27 AC 97 ms
12,612 KB
testcase_28 AC 56 ms
12,952 KB
testcase_29 AC 3 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long

const ll mod=998244353;
ll N;
vector<ll>G[1<<17];
ll dp[1<<17][3];

void dfs(ll u,ll p)
{
	ll a=1,b=0,c=0;
	for(ll v:G[u])if(v!=p)
	{
		dfs(v,u);
		ll na=a*(dp[v][0]+dp[v][1])%mod;
        ll nb=( b*(dp[v][0]+dp[v][1])+a*(dp[v][1]+dp[v][2]) )%mod;
		ll nc=( c*(dp[v][0]+dp[v][1])+b*(dp[v][1]+dp[v][2]) )%mod;
		a=na,b=nb,c=nc;
	}
	dp[u][0]=c;
	dp[u][1]=b;
	dp[u][2]=a;
}

int main()
{
	cin>>N;
	for(ll i=1;i<N;i++)
	{
		ll 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])%mod <<endl;
}
0