結果

問題 No.2047 Path Factory
ユーザー 👑 kmjpkmjp
提出日時 2022-08-19 22:21:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,469 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 198,180 KB
実行使用メモリ 23,876 KB
最終ジャッジ日時 2024-04-23 13:30:39
合計ジャッジ時間 3,952 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,644 KB
testcase_01 AC 4 ms
9,032 KB
testcase_02 AC 4 ms
8,388 KB
testcase_03 AC 4 ms
8,512 KB
testcase_04 AC 3 ms
8,256 KB
testcase_05 AC 4 ms
8,516 KB
testcase_06 AC 4 ms
8,772 KB
testcase_07 AC 32 ms
12,992 KB
testcase_08 AC 26 ms
11,200 KB
testcase_09 AC 31 ms
13,280 KB
testcase_10 AC 46 ms
13,508 KB
testcase_11 AC 25 ms
12,616 KB
testcase_12 AC 17 ms
11,588 KB
testcase_13 AC 16 ms
10,180 KB
testcase_14 AC 27 ms
10,948 KB
testcase_15 AC 31 ms
13,128 KB
testcase_16 AC 23 ms
11,588 KB
testcase_17 AC 24 ms
12,616 KB
testcase_18 AC 28 ms
14,148 KB
testcase_19 AC 33 ms
14,272 KB
testcase_20 AC 55 ms
16,192 KB
testcase_21 AC 28 ms
11,716 KB
testcase_22 AC 8 ms
10,692 KB
testcase_23 AC 10 ms
9,796 KB
testcase_24 AC 9 ms
9,668 KB
testcase_25 AC 42 ms
23,876 KB
testcase_26 AC 67 ms
21,448 KB
testcase_27 AC 60 ms
14,788 KB
testcase_28 AC 29 ms
14,680 KB
testcase_29 AC 4 ms
8,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
vector<int> E[202020];
ll dp[202020][2];
const ll mo=998244353;

void dfs(int cur,int pre) {
	ll from[3]={1,0,0};
	FORR(e,E[cur]) if(e!=pre) {
		dfs(e,cur);
		ll to[3]={};
		to[0]=(from[0]*dp[e][0])%mo;
		to[1]=(from[1]*dp[e][0]+from[0]*dp[e][1])%mo;
		to[2]=(from[1]*dp[e][1]+from[2]*dp[e][0])%mo;
		swap(from,to);
	}
	
	dp[cur][0]=(from[1]+from[2])%mo;
	dp[cur][1]=(from[0]+from[1])%mo;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	if(N==2) {
		cout<<1<<endl;
		return;
	}
	FOR(i,N) if(E[i].size()>=2) {
		dfs(i,i);
		cout<<dp[i][0]<<endl;
		return;
	}
	
		
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0