結果
| 問題 |
No.2047 Path Factory
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2022-08-19 21:54:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 148 ms / 2,000 ms |
| コード長 | 904 bytes |
| コンパイル時間 | 4,451 ms |
| コンパイル使用メモリ | 260,120 KB |
| 最終ジャッジ日時 | 2025-01-31 01:01:38 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int n;
vector<vector<int>> E;
vector<vector<mint>> dp;
void dfs(int cur,int p){
vector<mint> tdp(3,0);
tdp[0] = 1;
rep(i,E[cur].size()){
int to = E[cur][i];
if(to==p)continue;
dfs(to,cur);
vector<mint> ndp(3,0);
rep(j,3){
ndp[j] += tdp[j] * dp[to][1];
if(j!=2){
ndp[j+1] += tdp[j] * dp[to][0];
}
}
swap(tdp,ndp);
}
dp[cur][0] = tdp[0] + tdp[1];
dp[cur][1] = tdp[1] + tdp[2];
}
int main() {
cin>>n;
E.resize(n);
rep(i,n-1){
int u,v;
cin>>u>>v;
u--,v--;
E[u].push_back(v);
E[v].push_back(u);
}
dp.resize(n,vector<mint>(2,0));
dfs(0,-1);
mint ans = dp[0][1];
cout<<ans.val()<<endl;
return 0;
}
沙耶花